Skip navigation
Currently Being Moderated

Script that writes XMP also deleting dc:subject

May 24, 2011 3:02 PM

 

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.

Thanks

 

 

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)

docRef.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

 

 
Replies
  • Currently Being Moderated
    Nov 16, 2011 1:20 PM   in reply to inanealex2010

    I think you need to change this line:

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

     

    to this:

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points