1 Reply Latest reply on Nov 16, 2011 1:20 PM by gregreser

    Script that writes XMP also deleting dc:subject



      I found a javascript that allows Illustrator to write the contents of a variable to a specified NameSpace and Field. However, when it writes the XMP back to the file, it also clears the metadata in the dc:subject bag, which I don't want it to do. It is not clearing any of the metadata in any other Dublin Core fields or any of the fields of the specified namespace.


      Any ideas why this behavior happens? I want a solution, but I want to understand the behavior more.




      Script Follows:

      note: the variable "textContents" is defined in another part of the script not shown here.



      // 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("http://NameSpace.com/1.1", "NS:fullText", textContents);

      //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)