1 Reply Latest reply on Aug 28, 2010 7:39 PM by StevenErat

    How to write XMP changes back to Photoshop DOM in CS SDK?

    StevenErat Level 1

      Hello,

       

      I'm learning to use the ActionScript library for XMP in conjunction with the CS SDK to build Photoshop panels.

       

      I see from the Extension Builder samples that the AssetFragger application demonstrates how to use XMP for annotating comments to image files in Illustrator using com.adobe.illustrator.  In the runSet() method the XMP data is manipulated then the changes are stored in the document.  So after creating a new XMP node ( XMPArray.newBag() ) it uses doc.XMPString to write the serialized XMP back to the document, then sets doc.saved = false.

       

              public function runSet():void
              {
                  var app:Application = Illustrator.app;
                  var doc:Document = app.activeDocument;
                  var updateText:String = AssetFraggerModel.getInstance().xmlTextNugget;
                   var xmpString : String = doc.XMPString;
                  var xmpMeta : XMPMeta = new XMPMeta(xmpString);
                  var ns : Namespace = new Namespace(xmpMeta.getNamespace("xmp"));
                  xmpMeta.ns::AssetFraggerDescription = XMPArray.newBag();
                  xmpMeta.ns::AssetFraggerDescription[1] = updateText;
                  var tmp : String = xmpMeta.serialize();
                  doc.XMPString = tmp;   
                  doc.saved = false;
              }

       

       

      However, using com.adobe.photoshop instead, the XMLString property on the Application activeDocument instance is not available, the doc.saved property is not modifiable (marked as read-only), and the Photoshop Application activeDocument has a xmpMetadata.rawData property available whereas Illustrator did not.  The Photoshop activeDocument.xmpMetadata.rawData is marked as read only, so it can be used to get the plain XMP as a string directly, but once modified the XMP cannot be updated in that property.  Example:

       

              public static function traceXMP():void
              {
                  var app:Application = Photoshop.app;
                  var doc:Document = app.activeDocument;
                  var xmpString:String = doc.xmpMetadata.rawData;
                  var xmpMeta:XMPMeta = new XMPMeta(xmpString);
                  var metaXML:XML = xmpMeta.serializeToXML();
                  var Iptc4xmpCore:Namespace = new Namespace(XMPConst.Iptc4xmpCore);

       

                  // demonstrate that a leaf in IPTC can be changed and written to the trace console
                  xmpMeta.Iptc4xmpCore::CreatorContactInfo.Iptc4xmpCore::CiUrlWork = 'http://test.com/';
                  trace(ObjectUtil.toString(xmpMeta.Iptc4xmpCore::CreatorContactInfo.Iptc4xmpCore::CiUrlWor k.toString()));

       

                  // but now how to write the XMP change back to the Photoshop DOM?
              }

       

      My question is, for a given image file exported as from Lightroom that is rich in custom IPTC metadata, how does one update the metadata in Photosohp via XMP and the CS SDK?  I was not able to extract this information from the Advanced Topics: Working with XMP Metadata chapter of the CS SDK documentation

       

      A real, and complete code example would be greatly appreciated over a pseudocode example.

       

      Thank you in advance.

      Steven Erat