Copy link to clipboard
Copied
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
Thanks for your answer.
I don't know how to add metadata with custom namespace working on the InDesign document's MetadataPreference object.
In documentation (if I read well), it is written that document.metadataPreferences is a read-only property.
I tried to do it thanks to that :
var doc = app.activeDocument;
var metadataPreferences = doc.metadataPreferences;
metadataPreferences.setProperty("myNamespace", "myProperty", "myValue");
It doesn't work, even if I save document after that.
But, it seems to w
...Copy link to clipboard
Copied
Document file locking might have improved, if it previously worked I would consider that a bug.
Instead of ExtendScript's XMP library you could work straight on the InDesign document's MetadataPreference object ...
Copy link to clipboard
Copied
Thanks for your answer.
I don't know how to add metadata with custom namespace working on the InDesign document's MetadataPreference object.
In documentation (if I read well), it is written that document.metadataPreferences is a read-only property.
I tried to do it thanks to that :
var doc = app.activeDocument;
var metadataPreferences = doc.metadataPreferences;
metadataPreferences.setProperty("myNamespace", "myProperty", "myValue");
It doesn't work, even if I save document after that.
But, it seems to work with a known namespace like in this example :
var myDocXMP = app.activeDocument.metadataPreferences;
var destNamespace = "http://ns.adobe.com/xap/1.0/";
var destNodeName = "MyTesting";
var nodeValue = "test value";
myDocXMP.setProperty(destNamespace, destNodeName, nodeValue);
It seems like if I want to use custom namespace, I have to use this method :
var myXML = new XML("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><rdf:Description xmlns:TestXMP=\"https://test.wordpress.com/\"></rdf:Description></rdf:RDF></x:xmpmeta>");
var myXMLfile = File('C:/Users/myUser/Desktop/myTestXMP.xml');
if ( myXMLfile.open('e') ){
myXMLfile.write(myXML);
myXMLfile.close();
app.activeDocument.metadataPreferences.append(myXMLfile);
myXMLfile.remove();
}
var myDocXMP = app.activeDocument.metadataPreferences;
var destNamespace = "https://test.wordpress.com/";
var destNodeName = "MyTestingNode2";
var nodeValue = " test value";
myDocXMP.setProperty(destNamespace, destNodeName, nodeValue);
It seems to work on active document.
Reference :
Storing custom data into InDesign file via XMP | IndiSnip [InDesign® Snippets]