Javascript Photoshop中的getDocumentByName

Javascript Photoshop中的getDocumentByName,javascript,photoshop,photoshop-script,Javascript,Photoshop,Photoshop Script,虽然可以使用getByName获取图层、历史状态或图层集,但在使用两个或多个打开的Photoshop文件时,文档似乎没有 var srcDoc = app.Documents.getByName("Gwen_Stefani"); // doesn't work 是这样吗 在文档数组上循环直到字符串匹配所需文档的工作: getDocumentByName("Gwen_Stefani"); function getDocumentByName(docna

虽然可以使用getByName获取图层、历史状态或图层集,但在使用两个或多个打开的Photoshop文件时,文档似乎没有

var srcDoc = app.Documents.getByName("Gwen_Stefani"); // doesn't work
是这样吗

在文档数组上循环直到字符串匹配所需文档的工作:

getDocumentByName("Gwen_Stefani");


function getDocumentByName(docname)
{
  for (var i = 0; i < documents.length; i++)
  {
    var someDoc = docname.replace(/\..+$/, "");
    if (someDoc.toLowerCase() == docname.toLowerCase())
    {
      alert(someDoc);
      app.activeDocument = documents[i];
    }
  }
}
getDocumentByName(“Gwen_Stefani”);
函数getDocumentByName(docname)
{
对于(var i=0;i
不确定时,只需检查(第104页):

var srcDoc=documents.getByName(“Gwen_Stefani”);
activeDocument=srcDoc;
您还可以通过更可靠的ID激活文档:

//选择具有提供ID的文档
函数selectByID(id){
var desc=新的ActionDescriptor();
var ref=new ActionReference();
参考putIdentifier(charIDToTypeID(“Dcmn”),id);
desc.putReference(charIDToTypeID(“null”),ref);
执行(charIDToTypeID(“slct”)、描述、对话模式编号);
}
//获取活动文档的ID
函数getDocID(){
var ref=new ActionReference();
参考putProperty(stringIDToTypeID(“属性”)、stringIDToTypeID(“文档ID”);
ref.putEnumerated(charIDToTypeID(“Dcmn”)、stringIDToTypeID(“序号”)、stringIDToTypeID(“targetEnum”);
var desc=executeActionGet(ref);
返回desc.getInteger(stringIDToTypeID(“documentID”));
}

应该是
documents
,而不是
documents
getByName
,而不是
getByName
app.documents.getByName(“Gwen_Stefani”)GetByname-这是一个输入错误:D但是文件——我请客。就像忘记分机一样!谢谢@SergeyKritskiy把以上作为答案!