通过ExtendScript获取XMP文件没有构造函数错误

通过ExtendScript获取XMP文件没有构造函数错误

本文介绍了通过ExtendScript获取XMP文件没有构造函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OS上使用In Design CC 2019。当我尝试使用 ExtendScript为我的 .indd (InDesign文档)获取 XMP 数据时

I am using In Design CC 2019, on my Mac OS. When I am trying to get XMP data for my .indd (InDesign document) using ExtendScript.

我目前收到这样的错误:

I am currently getting the error like this:

下面是我的

// 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')
 }

推荐答案

您的代码逻辑存在问题,您需要进行以下更改:

There's an issue with your codes logic, you need to make the following change:


  1. 添加(即)达到为指定的条件 loadXMPLibrary 函数主体中的if 语句。

  1. Add the Logical NOT operator (i.e. !) to the condition specified for your if statement in the body of your loadXMPLibrary function.

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 ,因此,您所加载的代码实际上不会执行。

You need to add this because currently your if statement checks whether the condition is truthy, i.e. it checks whether ExternalObject.AdobeXMPScript is true. This will always remain false, until the AdobeXMPScript library has been loaded, therefore you're code that actually loads the library never gets executed.

修改后的脚本:

为清楚起见,这里是完整的修订本脚本:

For clarity here is the complete revised script:

// 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')
}

这篇关于通过ExtendScript获取XMP文件没有构造函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 02:10