在适用于Photoshop的Extendscript或Javascript中是否有任何等效的“ document.getElementById”?

时间:2018-12-19 17:27:24

标签: javascript adobe photoshop extendscript

我有一些Photoshop的ScriptListner插件代码。我正在尝试对ExtendScript使用“ document.getElementById('id').path = 'some path'”,实际上它只是修改过的JavaScript(据我所知),但是Photoshop JavaScript引擎似乎不支持。

我试图用'app.activeDocumnt'更改'文档',但这无济于事

function BuildContactSheet(sourceeFolder) {
  var idzeroBsevenoneDtwotwooneFeightCEoneonedtwoBtwooneBzerozerozeroeightCsevenfiveBthreetwotwoC = stringIDToTypeID("0B71D221-F8CE-11d2-B21B-0008C75B322C");
  var desc2 = new ActionDescriptor();
  var idCSIISettings = stringIDToTypeID("CSIISettings");
  desc2.putString(idCSIISettings, ""
    "<ContactSheetIISettings> <
    source id = "outPathsrc"
    imageSource = "Folder"
    path = "e"
    includeSubfolders = "false"
    groupImages = "false" / >
    <
    document units = "inches"
    width = "1.5"
    height = "2.4"
    resolution = "150"
    resUnits = "pixels/inch"
    mode = "RGB Color"
    bitDepth = "8-bit"
    colorProfile = "sRGB IEC61966-2.1"
    flattenLayers = "true" / >
    <
    thumbnail place = "across first"
    cols = "1"
    rows = "4"
    bestFit = "false"
    useAutospacing = "false"
    horz = "0.039 in"
    vert = "0.039 in" / >
    <
    caption enabled = "false" >
    <
    font name = "ArialMT"
    size = "12" / >
    <
    /caption> < /
    ContactSheetIISettings > ""
    " );
    var idMsge = charIDToTypeID("Msge"); desc2.putString(idMsge, ""
      "Settings for Contact Sheet II"
      ""); activeDocument.getElementById("outPathsrc").path = sourceeFolder;

    executeAction(idzeroBsevenoneDtwotwooneFeightCEoneonedtwoBtwooneBzerozerozeroeightCsevenfiveBthreetwotwoC, desc2, DialogModes.NO);

  }

此代码代码应该已经工作,并且根据我在函数中传递的参数更改了源文件夹,但不起作用。而是显示以下错误:

Error 1302: No such element
Line: 113
         activeDocument.getElementById("outPathsrc").path = sourceeFolder;

编辑: 我以前尝试过此方法,但它确实有效,我能够将参数传递给该函数!

“代码”

function dividePic(outFolder){
    var idExpr = charIDToTypeID( "Expr" );
        var desc104 = new ActionDescriptor();
        var idUsng = charIDToTypeID( "Usng" );
            var desc105 = new ActionDescriptor();
            var idOp = charIDToTypeID( "Op  " );
            var idSWOp = charIDToTypeID( "SWOp" );
            var idOpSa = charIDToTypeID( "OpSa" );
            desc105.putEnumerated( idOp, idSWOp, idOpSa );
            var idDIDr = charIDToTypeID( "DIDr" );
            desc105.putBoolean( idDIDr, true );
            var idIn = charIDToTypeID( "In  " );
            desc105.putPath( idIn, new File(outFolder) ); //THE ARGUMENT IS HERE!!!!
            var idFmt = charIDToTypeID( "Fmt " );
            var idIRFm = charIDToTypeID( "IRFm" );
            var idJPEG = charIDToTypeID( "JPEG" );
            desc105.putEnumerated( idFmt, idIRFm, idJPEG );
            var idIntr = charIDToTypeID( "Intr" );
            desc105.putBoolean( idIntr, false );
            var idQlty = charIDToTypeID( "Qlty" );
            desc105.putInteger( idQlty, 30 );
            var idQChS = charIDToTypeID( "QChS" );
            desc105.putInteger( idQChS, 0 );
            var idQCUI = charIDToTypeID( "QCUI" );
            desc105.putInteger( idQCUI, 0 );
            var idQChT = charIDToTypeID( "QChT" );
            desc105.putBoolean( idQChT, false );
            var idQChV = charIDToTypeID( "QChV" );
            desc105.putBoolean( idQChV, false );
            var idOptm = charIDToTypeID( "Optm" );
            desc105.putBoolean( idOptm, true );
            var idPass = charIDToTypeID( "Pass" );
            desc105.putInteger( idPass, 1 );
            var idblur = charIDToTypeID( "blur" );
            desc105.putDouble( idblur, 0.000000 );
            var idMtt = charIDToTypeID( "Mtt " );
            desc105.putBoolean( idMtt, true );
            var idEICC = charIDToTypeID( "EICC" );
            desc105.putBoolean( idEICC, false );
            var idMttR = charIDToTypeID( "MttR" );
            desc105.putInteger( idMttR, 255 );
            var idMttG = charIDToTypeID( "MttG" );
            desc105.putInteger( idMttG, 255 );
            var idMttB = charIDToTypeID( "MttB" );
            desc105.putInteger( idMttB, 255 );
            var idSHTM = charIDToTypeID( "SHTM" );
            desc105.putBoolean( idSHTM, false );
            var idSImg = charIDToTypeID( "SImg" );
            desc105.putBoolean( idSImg, true );
            var idSWsl = charIDToTypeID( "SWsl" );
            var idSTsl = charIDToTypeID( "STsl" );
            var idSLAl = charIDToTypeID( "SLAl" );
            desc105.putEnumerated( idSWsl, idSTsl, idSLAl );
            var idSWch = charIDToTypeID( "SWch" );
            var idSTch = charIDToTypeID( "STch" );
            var idCHsR = charIDToTypeID( "CHsR" );
            desc105.putEnumerated( idSWch, idSTch, idCHsR );
            var idSWmd = charIDToTypeID( "SWmd" );
            var idSTmd = charIDToTypeID( "STmd" );
            var idMDCC = charIDToTypeID( "MDCC" );
            desc105.putEnumerated( idSWmd, idSTmd, idMDCC );
            var idohXH = charIDToTypeID( "ohXH" );
            desc105.putBoolean( idohXH, false );
            var idohIC = charIDToTypeID( "ohIC" );
            desc105.putBoolean( idohIC, true );
            var idohAA = charIDToTypeID( "ohAA" );
            desc105.putBoolean( idohAA, true );
            var idohQA = charIDToTypeID( "ohQA" );
            desc105.putBoolean( idohQA, true );
            var idohCA = charIDToTypeID( "ohCA" );
            desc105.putBoolean( idohCA, false );
            var idohIZ = charIDToTypeID( "ohIZ" );
            desc105.putBoolean( idohIZ, true );
            var idohTC = charIDToTypeID( "ohTC" );
            var idSToc = charIDToTypeID( "SToc" );
            var idOCzerothree = charIDToTypeID( "OC03" );
            desc105.putEnumerated( idohTC, idSToc, idOCzerothree );
            var idohAC = charIDToTypeID( "ohAC" );
            var idSToc = charIDToTypeID( "SToc" );
            var idOCzerothree = charIDToTypeID( "OC03" );
            desc105.putEnumerated( idohAC, idSToc, idOCzerothree );
            var idohIn = charIDToTypeID( "ohIn" );
            desc105.putInteger( idohIn, -1 );
            var idohLE = charIDToTypeID( "ohLE" );
            var idSTle = charIDToTypeID( "STle" );
            var idLEzerothree = charIDToTypeID( "LE03" );
            desc105.putEnumerated( idohLE, idSTle, idLEzerothree );
            var idohEn = charIDToTypeID( "ohEn" );
            var idSTen = charIDToTypeID( "STen" );
            var idENzerozero = charIDToTypeID( "EN00" );
            desc105.putEnumerated( idohEn, idSTen, idENzerozero );
            var idolCS = charIDToTypeID( "olCS" );
            desc105.putBoolean( idolCS, false );
            var idolEC = charIDToTypeID( "olEC" );
            var idSTst = charIDToTypeID( "STst" );
            var idSTzerozero = charIDToTypeID( "ST00" );
            desc105.putEnumerated( idolEC, idSTst, idSTzerozero );
            var idolWH = charIDToTypeID( "olWH" );
            var idSTwh = charIDToTypeID( "STwh" );
            var idWHzeroone = charIDToTypeID( "WH01" );
            desc105.putEnumerated( idolWH, idSTwh, idWHzeroone );
            var idolSV = charIDToTypeID( "olSV" );
            var idSTsp = charIDToTypeID( "STsp" );
            var idSPzerofour = charIDToTypeID( "SP04" );
            desc105.putEnumerated( idolSV, idSTsp, idSPzerofour );
            var idolSH = charIDToTypeID( "olSH" );
            var idSTsp = charIDToTypeID( "STsp" );
            var idSPzerofour = charIDToTypeID( "SP04" );
            desc105.putEnumerated( idolSH, idSTsp, idSPzerofour );
            var idolNC = charIDToTypeID( "olNC" );
                var list5 = new ActionList();
                    var desc106 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCzerozero = charIDToTypeID( "NC00" );
                    desc106.putEnumerated( idncTp, idSTnc, idNCzerozero );
                var idSCnc = charIDToTypeID( "SCnc" );
                list5.putObject( idSCnc, desc106 );
                    var desc107 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNConenine = charIDToTypeID( "NC19" );
                    desc107.putEnumerated( idncTp, idSTnc, idNConenine );
                var idSCnc = charIDToTypeID( "SCnc" );
                list5.putObject( idSCnc, desc107 );
                    var desc108 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCtwoeight = charIDToTypeID( "NC28" );
                    desc108.putEnumerated( idncTp, idSTnc, idNCtwoeight );
                var idSCnc = charIDToTypeID( "SCnc" );
                list5.putObject( idSCnc, desc108 );
                    var desc109 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCtwofour = charIDToTypeID( "NC24" );
                    desc109.putEnumerated( idncTp, idSTnc, idNCtwofour );
                var idSCnc = charIDToTypeID( "SCnc" );
                list5.putObject( idSCnc, desc109 );
                    var desc110 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCtwofour = charIDToTypeID( "NC24" );
                    desc110.putEnumerated( idncTp, idSTnc, idNCtwofour );
                var idSCnc = charIDToTypeID( "SCnc" );
                list5.putObject( idSCnc, desc110 );
                    var desc111 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCtwofour = charIDToTypeID( "NC24" );
                    desc111.putEnumerated( idncTp, idSTnc, idNCtwofour );
                var idSCnc = charIDToTypeID( "SCnc" );
                list5.putObject( idSCnc, desc111 );
            desc105.putList( idolNC, list5 );
            var idobIA = charIDToTypeID( "obIA" );
            desc105.putBoolean( idobIA, false );
            var idobIP = charIDToTypeID( "obIP" );
            desc105.putString( idobIP, """""" );
            var idobCS = charIDToTypeID( "obCS" );
            var idSTcs = charIDToTypeID( "STcs" );
            var idCSzeroone = charIDToTypeID( "CS01" );
            desc105.putEnumerated( idobCS, idSTcs, idCSzeroone );
            var idovNC = charIDToTypeID( "ovNC" );
                var list6 = new ActionList();
                    var desc112 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCzeroone = charIDToTypeID( "NC01" );
                    desc112.putEnumerated( idncTp, idSTnc, idNCzeroone );
                var idSCnc = charIDToTypeID( "SCnc" );
                list6.putObject( idSCnc, desc112 );
                    var desc113 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCtwozero = charIDToTypeID( "NC20" );
                    desc113.putEnumerated( idncTp, idSTnc, idNCtwozero );
                var idSCnc = charIDToTypeID( "SCnc" );
                list6.putObject( idSCnc, desc113 );
                    var desc114 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCzerotwo = charIDToTypeID( "NC02" );
                    desc114.putEnumerated( idncTp, idSTnc, idNCzerotwo );
                var idSCnc = charIDToTypeID( "SCnc" );
                list6.putObject( idSCnc, desc114 );
                    var desc115 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNConenine = charIDToTypeID( "NC19" );
                    desc115.putEnumerated( idncTp, idSTnc, idNConenine );
                var idSCnc = charIDToTypeID( "SCnc" );
                list6.putObject( idSCnc, desc115 );
                    var desc116 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCzerosix = charIDToTypeID( "NC06" );
                    desc116.putEnumerated( idncTp, idSTnc, idNCzerosix );
                var idSCnc = charIDToTypeID( "SCnc" );
                list6.putObject( idSCnc, desc116 );
                    var desc117 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCtwofour = charIDToTypeID( "NC24" );
                    desc117.putEnumerated( idncTp, idSTnc, idNCtwofour );
                var idSCnc = charIDToTypeID( "SCnc" );
                list6.putObject( idSCnc, desc117 );
                    var desc118 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCtwofour = charIDToTypeID( "NC24" );
                    desc118.putEnumerated( idncTp, idSTnc, idNCtwofour );
                var idSCnc = charIDToTypeID( "SCnc" );
                list6.putObject( idSCnc, desc118 );
                    var desc119 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCtwofour = charIDToTypeID( "NC24" );
                    desc119.putEnumerated( idncTp, idSTnc, idNCtwofour );
                var idSCnc = charIDToTypeID( "SCnc" );
                list6.putObject( idSCnc, desc119 );
                    var desc120 = new ActionDescriptor();
                    var idncTp = charIDToTypeID( "ncTp" );
                    var idSTnc = charIDToTypeID( "STnc" );
                    var idNCtwotwo = charIDToTypeID( "NC22" );
                    desc120.putEnumerated( idncTp, idSTnc, idNCtwotwo );
                var idSCnc = charIDToTypeID( "SCnc" );
                list6.putObject( idSCnc, desc120 );
            desc105.putList( idovNC, list6 );
            var idovCM = charIDToTypeID( "ovCM" );
            desc105.putBoolean( idovCM, false );
            var idovCW = charIDToTypeID( "ovCW" );
            desc105.putBoolean( idovCW, true );
            var idovCU = charIDToTypeID( "ovCU" );
            desc105.putBoolean( idovCU, true );
            var idovSF = charIDToTypeID( "ovSF" );
            desc105.putBoolean( idovSF, true );
            var idovCB = charIDToTypeID( "ovCB" );
            desc105.putBoolean( idovCB, true );
            var idovSN = charIDToTypeID( "ovSN" );
            desc105.putString( idovSN, """images""" );
        var idSaveForWeb = stringIDToTypeID( "SaveForWeb" );
        desc104.putObject( idUsng, idSaveForWeb, desc105 );
    executeAction( idExpr, desc104, DialogModes.NO );

}

“代码”

2 个答案:

答案 0 :(得分:1)

.getElementById是html DOM方法,photoshop不支持。您可以检查https://www.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-cc-javascript-ref-2019.pdf以查看支持哪些方法。另外,您不能真正混合使用Photoshop DOM和动作管理器代码(您从scriptlistener获得的较低级代码)。

答案 1 :(得分:1)

我不确定自己要做什么,但是如果您在谈论文件路径中的路径,这可能是读取文件夹内容的一个示例:

var folder = new Folder("~/Desktop/Test Folder/");
var files = folder.getFiles();

如果您要获取活动文档的路径,则为app.activeDocument.path

正如Sergey所说,更改脚本侦听器代码可能很简单。