Skip to main content
Inspiring
June 5, 2009
Answered

Edit Metadata inside Illustrator

  • June 5, 2009
  • 4 replies
  • 10511 views

Can anyone please tell me how to edit the XMP Packet, while inside of Illustrator, without using FileInfo?   I am writing a Flex PatchPanel Extension, so need access to some DOM parameter like XMPString to change the packet.  XMPString does not say it is READ ONLY in the reference manual -- but does not let me change it -- unless I am doing something wrong.

Thanks for any suggestion.

Correct answer majorLaser

For my setup I have an external program that saves an xmp packet (not rdf) to a file. Using a script in Ilustrator I then read that packet and append it to the active documents existing xmp using XMPFile and XMPUtils. The updated xmp is then saved to the active document using XMPFile and putXmp.

You should be able to skip the external xmp file part and use the setProperty() method directly on a copy of the active documents xmp and then save that back to the .ai file.

Here's a simplified (and working) example as it's easier to explain with code:

// Load the XMP Script library

if( xmpLib == undefined ) {

var xmpLib = new ExternalObject("lib:../../Frameworks/AdobeXMPScript");

app.synchronousMode = true;

}

//Create an XMPMeta object from the active documents XMPString:

var docXmp = new XMPMeta(app.activeDocument.XMPString);

//Make a copy that we can work with:

var myXmp = docXmp;

//Make our changes:

myXmp.setProperty(XMPConst.NS_XMP, "CreatorTool", "My Script");

//Append the modified xmp to the original xmp object:

XMPUtils.appendProperties(myXmp, docXmp, XMPConst.APPEND_REPLACE_OLD_VALUES);

//Create a File object of the active document so we can use .fsName (XMPFile seems to be picky):

var myDocFile = new File(app.activeDocument.fullName);

//Open the active document for writing:

var docRef = new XMPFile(myDocFile.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

//Check that we can write the xmp before writing it

if (docRef.canPutXMP(docXmp)) { docRef.putXMP(docXmp); }

//Save the active document (user will have to re-open file to see updated xmp in file info panel)

docRef.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

Most of what I've learned about the xmp library came from the following pdf so if you haven't already you should check it out:

http://www.adobe.com/devnet/scripting/estk/pdfs/javascript_tools_guide_cs3.pdf

HTH.

4 replies

frax_-L75d7K
Known Participant
May 31, 2010

Just playing with this - how can I change the title property? (in the DC namespace)

I can read/write properties in the NS_XMP namespace, but I am having trouble to get something to work in the others... !

Inspiring
July 7, 2009

I've never tried to do it from a string but I've had good success with importing xmp from an external file (my.xmp). Once the external xmp is loaded you can use the XMLUtils to append the external xmp to the xmp in the AI.

tstorb1Author
Inspiring
July 7, 2009

Thanks for your reply, but I need more help to understand if this is possible...

I have a flex panel that is a palette, that allows the user to enter metadata about the file - just like a custom file info panel - but running as an extension palette, using patch panel - I have to manage the read and write of the xmp packet through AI scripting DOM.

I do not see anything that allows reading and writing the xmppacket -- while inside of Illustrator.    XMLutil provides a way to parse the xmp packet, right?

As does the XMP Library for AS, but the issue is how to embed in the packet - while inside of Illustrator.  I can do this easily with Photoshop, Indesign, Bridge - (or I could write a C++ extension) -- but I would like to script it.

Can you give more details how you have done this, I assume you mean after the user saves the AI file, you then have to append the xmp to the file, outside of AI?   If so, you say xmlutis allows you to append xmp packet to an AI file?

Thanks for your help.

majorLaserCorrect answer
Inspiring
July 8, 2009

For my setup I have an external program that saves an xmp packet (not rdf) to a file. Using a script in Ilustrator I then read that packet and append it to the active documents existing xmp using XMPFile and XMPUtils. The updated xmp is then saved to the active document using XMPFile and putXmp.

You should be able to skip the external xmp file part and use the setProperty() method directly on a copy of the active documents xmp and then save that back to the .ai file.

Here's a simplified (and working) example as it's easier to explain with code:

// Load the XMP Script library

if( xmpLib == undefined ) {

var xmpLib = new ExternalObject("lib:../../Frameworks/AdobeXMPScript");

app.synchronousMode = true;

}

//Create an XMPMeta object from the active documents XMPString:

var docXmp = new XMPMeta(app.activeDocument.XMPString);

//Make a copy that we can work with:

var myXmp = docXmp;

//Make our changes:

myXmp.setProperty(XMPConst.NS_XMP, "CreatorTool", "My Script");

//Append the modified xmp to the original xmp object:

XMPUtils.appendProperties(myXmp, docXmp, XMPConst.APPEND_REPLACE_OLD_VALUES);

//Create a File object of the active document so we can use .fsName (XMPFile seems to be picky):

var myDocFile = new File(app.activeDocument.fullName);

//Open the active document for writing:

var docRef = new XMPFile(myDocFile.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

//Check that we can write the xmp before writing it

if (docRef.canPutXMP(docXmp)) { docRef.putXMP(docXmp); }

//Save the active document (user will have to re-open file to see updated xmp in file info panel)

docRef.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

Most of what I've learned about the xmp library came from the following pdf so if you haven't already you should check it out:

http://www.adobe.com/devnet/scripting/estk/pdfs/javascript_tools_guide_cs3.pdf

HTH.

tstorb1Author
Inspiring
June 13, 2009

One last try, to find a way to edit xmp packet with a script inside Illstrator...  XMPString, is it edit only?

Any other idea?

A simple informed, no way to do it, would be also help at this point.

thanks!

frax_-L75d7K
Known Participant
June 15, 2009

At some point I downloaded the XMP SDK, which I haven't really peeked at more - have you looked at that?

tstorb1Author
Inspiring
June 15, 2009

Yes, that does not help for scripting inside of Illustrator.  The problem is the Illustrator team - I am starting to assume - did not implement the Javascript XMP API, like the other CS teams did, to allow for adjusting the XMP packet in their DOM -- just like they don't follow the methods for allowing event management, like the other CS apps did....notice a trend here for the AI team?

Larry G. Schneider
Community Expert
Community Expert
June 5, 2009

Can you write the XMPString to a text file outside of AI, modify it and then replace the existing string? You're right in that it doesn't say it is read only but it sounds like it is from inside AI.

Wait, have you saved an AI file without compression and then looked in the resulting AI file with a text editor. I tried this the other day and seem to remember a whole bunch of xmp statements listed.

tstorb1Author
Inspiring
June 5, 2009

No.  I tried to replace it several ways, but nothing has worked yet.