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小白……

https://blog.csdn.net/oldboy1234/article/details/108623