我试图在脚本中访问当前打开的文档,但它未定义。但是我已经在Photoshop中打开了文档。我应该初始化它吗?这是我的代码
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();
为了让它工作
g_rootDoc = app.activeDocument;
需要在函数之外(除非您将源文档传递给该函数)。
修改代码:
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()
{
}
如果你在一个窗口中运行photoshop,在另一个窗口中运行ExtendedScript中的代码,你需要添加第一行
" #目标photoshop "
(没有双标记)在你的js脚本。
在我的例子中,问题是由遗漏的变量名引起的:
function fnWithError() {
var docName = app.activeDocument.name // <- ExtendScript Toolkit reports error here.
...
...
var app.activeDocument.activeLayer.bounds;// <- The real error is here.
// the code above should be:
// var bounds = app.activeDocument.activeLayer.bounds;
}