通过 ExtendScript 获取 XMP 文件没有构造函数错误
getting XMP File does not have a constructor error through ExtendScript
我在 Mac OS 上使用 In Design CC 2019。当我尝试使用 ExtendScript
.
为我的 .indd
(InDesign 文档)获取 XMP
数据时
我目前收到这样的错误:
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')
}
您的代码逻辑有问题,您需要进行以下更改:
将 Logical NOT operator(即 !
)添加到 loadXMPLibrary
函数主体中为 if
语句指定的条件。
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
。这将始终保持 false
,直到 AdobeXMPScript 库被加载,因此您实际加载库的代码永远不会被执行。
修改后的脚本:
为清楚起见,这里是完整的修订脚本:
// 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')
}
我在 Mac OS 上使用 In Design CC 2019。当我尝试使用 ExtendScript
.
.indd
(InDesign 文档)获取 XMP
数据时
我目前收到这样的错误:
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')
}
您的代码逻辑有问题,您需要进行以下更改:
将 Logical NOT operator(即
!
)添加到loadXMPLibrary
函数主体中为if
语句指定的条件。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
。这将始终保持false
,直到 AdobeXMPScript 库被加载,因此您实际加载库的代码永远不会被执行。
修改后的脚本:
为清楚起见,这里是完整的修订脚本:
// 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')
}