Copy link to clipboard
Copied
Hi,
I found this script to write XMP metadata to an open file, but it does not seem to work for me in Illustrator CC. The error message is "XMP exception: Source and destination XMP must differ".
Is there perhaps an alternative method of writing properties to the XMP fields?
Thanks,
Rich
if( xmpLib == undefined ) {
var xmpLib = new ExternalObject("lib:../../Frameworks/AdobeXMPScript");
app.synchronousMode = true;
}
var docXmp = new XMPMeta(app.activeDocument.XMPString);
var myXmp = docXmp;
myXmp.setProperty(XMPConst.NS_XMP, "CreatorTool", "My Script");
XMPUtils.appendProperties(myXmp, docXmp, XMPConst.APPEND_ALL_PROPERTIES);
var myDocFile = new File(app.activeDocument.fullName);
var docRef = new XMPFile(myDocFile.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
if (docRef.canPutXMP(docXmp)) { docRef.putXMP(docXmp); }
docRef.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
Copy link to clipboard
Copied
Is that all your script or just part of it…? Either way it's got a line that is Bridge script…
app.synchronousMode = true; // This ONLY applies to the Bridge App…
Copy link to clipboard
Copied
It's just part of the script. I want to test if I can write metadata information to the illustrator file. I can then go on target specific fields.
I've removed the Bridge script line, but it's still showing the same error.
Copy link to clipboard
Copied
After much searching I discovered another script that does the trick. The document must be closed and then reopened to view the modifications (took me a while to realise 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;
}
// select destination file
var myFile = File.openDialog("Select destination file", "Illustrator:*.ai", false);
// check library and file
if(loadXMPLibrary() && myFile != null){
xmpFile = new XMPFile(myFile.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = xmpFile.getXMP();
}
if(myXmp){
// change Document title to Foo
myXmp.setProperty(XMPConst.NS_DC, "title", "Foo");
// put XMP into file
if (xmpFile.canPutXMP(myXmp)){xmpFile.putXMP(myXmp);}else{alert("Error storing XMP");}
// close file
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
// credit to tomaxxi for this script