myjconan 2020-07-02 11:13 采纳率: 0%
浏览 119

PS运行js脚本提示:liveobject()不是函数

功能大致如下:根据图片名称、字数创建若干文字层,并调整字号与位置,以下是字数小于15的情况的代码。文字居中部分使用的是监听出来的脚本。

var docRef=activeDocument

app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS

var h = app.activeDocument.height
var w = app.activeDocument.width

var docname =activeDocument.name
var Dot = docname.lastIndexOf('.')
var rdocname = docname.substring(0,Dot)

//alert(rdocname.length)

if (rdocname.length<16) {

var layerRef=docRef.artLayers.add()
layerRef.kind=LayerKind.TEXT
var textItemRef=layerRef.textItem

var textcolor= new SolidColor
textcolor.rgb.red=255
textcolor.rgb.green=255
textcolor.rgb.blue=255
textItemRef.color=textcolor

textItemRef.font= "楷体"

textItemRef.contents = rdocname

textItemRef.size=29-rdocname.length
textItemRef.justification=Justification.CENTER


//监听居中代码

///////////////////////////////////////////////////////////////////////////////
(function select_17263603303581()   //
    {
    try {
alert("1")
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putName(stringIDToTypeID("layer"), "从不四渡 赤水");
        d.putReference(stringIDToTypeID("null"), r);
        d.putBoolean(stringIDToTypeID("makeVisible"), false);
        var list = new ActionList();
        list.putInteger(88);
        d.putList(stringIDToTypeID("layerID"), list);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
        }
    catch (e) { if (e.number!=8007) { alert("Line: "+e.line+"\n\n"+e,"Bug!",true); throw(e); } }
    }
)();


///////////////////////////////////////////////////////////////////////////////
function select_4938085838221() //删除图层
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putName(stringIDToTypeID("layer"), "底图");
        d.putReference(stringIDToTypeID("null"), r);
        d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelectionContinuous"));
        d.putBoolean(stringIDToTypeID("makeVisible"), false);
        var list = new ActionList();
        list.putInteger(84);
        list.putInteger(88);
        d.putList(stringIDToTypeID("layerID"), list);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
        }
    catch (e) { if (e.number!=8007) { alert("Line: "+e.line+"\n\n"+e,"Bug!",true); throw(e); } }
    }


///////////////////////////////////////////////////////////////////////////////
function align_53377254167572() //水平居中对齐
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);
        d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
        d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
        executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
        }
    catch (e) { if (e.number!=8007) { alert("Line: "+e.line+"\n\n"+e,"Bug!",true); throw(e); } }
    }


///////////////////////////////////////////////////////////////////////////////
function align_11511212121695() //
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);
        d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
        d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
        executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
        }
    catch (e) { if (e.number!=8007) { alert("Line: "+e.line+"\n\n"+e,"Bug!",true); throw(e); } }
    }
///////////////////////////////////////////////////////////////////////////////
function align_68942219391465() //垂直居中对齐
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);
        d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersV"));
        d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
        executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
        }
    catch (e) { if (e.number!=8007) { alert("Line: "+e.line+"\n\n"+e,"Bug!",true); throw(e); } }
    }


///////////////////////////////////////////////////////////////////////////////
function align_11881851917133() //
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);
        d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersV"));
        d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
        executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
        }
    catch (e) { if (e.number!=8007) { alert("Line: "+e.line+"\n\n"+e,"Bug!",true); throw(e); } }
    }

}

还望大神不吝赐教,另外如果我想在function SELECT……这些函数里面传递rdocname参数可以吗,比如把“从不四渡 赤水”改成rdocname?要如何编写呢?本人JS小白……

  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等