我在Mac OS上使用In Design CC 2019。当我尝试使用XMP
获取.indd
(InDesign文档)的ExtendScript
数据时。
我目前收到这样的错误:
XMPFile Does not have a constructor
。
下面是我的脚本。
// load XMP Library
function loadXMPLibrary(){
if ( ExternalObject.AdobeXMPScript){
try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}
catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}
}
return true;
}
var myFile= app.activeDocument.fullName;
// check library and file
if(loadXMPLibrary() && myFile != null){
xmpFile = new XMPFile(myFile.fsName, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = xmpFile.getXMP();
}
if(myXmp){
$.writeln ('sucess')
}
答案 0 :(得分:1)
您的代码逻辑存在问题,您需要进行以下更改:
在!
函数主体中为if
语句指定的条件中添加Logical NOT operator(即loadXMPLibrary
)。
function loadXMPLibrary(){
if (!ExternalObject.AdobeXMPScript) { // <--- Change to this
// ^
try {ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}
catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}
}
return true;
}
您需要添加它,因为当前您的if
语句检查条件是否为真,即它检查ExternalObject.AdobeXMPScript
是否为true
。在加载AdobeXMPScript库之前,它将一直保持false
的状态,因此您实际上是从未加载该库的代码。
修订后的脚本:
为清楚起见,以下是完整的修订脚本:
// load XMP Library
function loadXMPLibrary() {
if (!ExternalObject.AdobeXMPScript) {
try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}
catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}
}
return true;
}
var myFile= app.activeDocument.fullName;
// check library and file
if (loadXMPLibrary() && myFile !== null) {
xmpFile = new XMPFile(myFile.fsName, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = xmpFile.getXMP();
}
if (myXmp){
$.writeln ('success')
}