Update metadata on active document
Hi,
I'm trying to add new XMP metadata on active document in InDesign CC2018 and it doesn't work.
If I run my code on a closed indesign file, it works.
What's wrong ? We could update metadata on active document, couldn't we ?
Here is my code :
// 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){
var destNamespace = "myNamespace";
// define new namespace
XMPMeta.registerNamespace(destNamespace,"ns2");
// insert nodes
myXmp.setProperty(destNamespace,"creator","creator1");
[...]
// put XMP into file
if (xmpFile.canPutXMP(myXmp)){xmpFile.putXMP(myXmp);}else{alert("Error storing XMP");}
// close file
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
Got this exception :
XMP Exception : Open, other failure
Thanks
