1

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:

XMPFile Does not have a constructor.

Below is my 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 ('sucess')
 }

enter image description here

enter image description here

RobC
  • 22,977
  • 20
  • 73
  • 80
Madasu K
  • 1,813
  • 2
  • 38
  • 72

1 Answers1

1

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

  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;
    }
    

    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.

Revised script:

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')
}
RobC
  • 22,977
  • 20
  • 73
  • 80
  • Hi RobC, could you please suggest any video tutorial for me to work on XMP data using extendscript in InDesign CC 2019. Even paid tutorials are also fine. I have already read JavascriptToolsGuide.pdf and XMPFilePlugin.pdf. Because I need to work extensively in Meta data modification of .indd files. My task is, I need to access all the links associated with .indd file and then see each of those links meta data contains documentID and instanceID, if any of the links miss these then I need to display error message with their file names – Madasu K May 15 '19 at 10:38
  • Hi Madasu, unfortunately I'm not aware of any videos or tutorials on the topic. You may find _"Chapter 10 - Scripting Access to XMP Metadata"_ useful - it contains several code examples and can be found [here](https://estk.aenhancers.com/index.html) - it's more of a reference than a step-by-step tutorial though. – RobC May 15 '19 at 10:51
  • Thanks RobC. I have just added var proj = app.project to your script but it is giving me the error, Cannot execute script in target engine 'main'! (#55) Object does not support the property or method 'project'. I have attached the screen shot also for reference. Any suggestions to fix this error. I am just trying to make work the code sample at https://forums.adobe.com/thread/1302473. – Madasu K May 15 '19 at 11:04
  • 1
    The example [here](https://forums.adobe.com/thread/1302473) (i.e. the one that you provided in your comment) is for scripting _Adobe After Effects_ and not _Adobe inDesign_. So the error message your getting is correct because inDesign does not have a property or method called `project` associated with the `app` object. – RobC May 15 '19 at 11:20