Photoshop scripting: app.activeDocument is undefined

独自空忆成欢 提交于 2019-12-24 12:21:51

问题


I'm trying to access current opened document in script, but it's undefined. But i have opened document in Photoshop. Should i initialize it somehow? Here is my code

function ProcessDocumentWithoutXML()
{  
g_rootDoc      = app.activeDocument;
g_progBar      = new ProgressBar();

if (app.activeDocument != null)
{
    ProcessLayersWithoutXML(g_rootDoc);
    alert("Done!");
} else {
    alert("Missing active document");
}
}

ProcessDocumentWithoutXML();

回答1:


In order for it to work

g_rootDoc      = app.activeDocument;

needs to be outside the function (unless you pass in the source document to that function).

Amended code:

if (documents.length != 0)
{
   g_rootDoc = app.activeDocument;
   // g_progBar = new ProgressBar();  // no worky in cs2
   ProcessLayersWithoutXML(g_rootDoc);
   alert("Done!");
}
else
{
    alert("Missing active document");
}


function ProcessDocumentWithoutXML()
{  

}

ProcessDocumentWithoutXML();

function ProcessLayersWithoutXML()
{
}



回答2:


If you are running photoshop in one window and running your code in ExtendedScript in other window you need to add the first line

"#target photoshop"

(without double marks) on your js script.



来源:https://stackoverflow.com/questions/22507109/photoshop-scripting-app-activedocument-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!