• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Update metadata on active document

Explorer ,
Jun 29, 2018 Jun 29, 2018

Copy link to clipboard

Copied

Hi,

I'm trying to add new XMP metadata on active document in InDesign CC2018 and it doesn't work.

If I run my code on a closed indesign file, it works.

What's wrong ? We could update metadata on active document, couldn't we  ?

Here is my code :

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

}

var myFile= app.activeDocument.fullName;

// check library and file

if(loadXMPLibrary() && myFile != null){

   xmpFile = new XMPFile(myFile.fsName, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_UPDATE); 

   var myXmp = xmpFile.getXMP();

}

if(myXmp){

    var destNamespace = "myNamespace";

    // define new namespace

    XMPMeta.registerNamespace(destNamespace,"ns2");

    // insert nodes

    myXmp.setProperty(destNamespace,"creator","creator1");

    [...]

    // put XMP into file

    if (xmpFile.canPutXMP(myXmp)){xmpFile.putXMP(myXmp);}else{alert("Error storing XMP");}

    // close file

    xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

}

Got this exception :

XMP Exception : Open, other failure

Thanks

TOPICS
Scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jul 02, 2018 Jul 02, 2018

Thanks for your answer.

I don't know how to add metadata with custom namespace working on the InDesign document's MetadataPreference object.
In documentation (if I read well), it is written that document.metadataPreferences is a read-only property.

I tried to do it thanks to that :

var doc = app.activeDocument;

var metadataPreferences = doc.metadataPreferences;

metadataPreferences.setProperty("myNamespace", "myProperty", "myValue");

It doesn't work, even if I save document after that.

But, it seems to w

...

Votes

Translate

Translate
Guide ,
Jul 01, 2018 Jul 01, 2018

Copy link to clipboard

Copied

Document file locking might have improved, if it previously worked I would consider that a bug.

Instead of ExtendScript's XMP library you could work straight on the InDesign document's MetadataPreference object ...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 02, 2018 Jul 02, 2018

Copy link to clipboard

Copied

LATEST

Thanks for your answer.

I don't know how to add metadata with custom namespace working on the InDesign document's MetadataPreference object.
In documentation (if I read well), it is written that document.metadataPreferences is a read-only property.

I tried to do it thanks to that :

var doc = app.activeDocument;

var metadataPreferences = doc.metadataPreferences;

metadataPreferences.setProperty("myNamespace", "myProperty", "myValue");

It doesn't work, even if I save document after that.

But, it seems to work with a known namespace like in this example :

var myDocXMP = app.activeDocument.metadataPreferences;

var destNamespace = "http://ns.adobe.com/xap/1.0/";

var destNodeName = "MyTesting";

var nodeValue = "test value";

myDocXMP.setProperty(destNamespace, destNodeName, nodeValue);

It seems like if I want to use custom namespace, I have to use this method :

var myXML = new XML("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><rdf:Description xmlns:TestXMP=\"https://test.wordpress.com/\"></rdf:Description></rdf:RDF></x:xmpmeta>");

var myXMLfile = File('C:/Users/myUser/Desktop/myTestXMP.xml');

if ( myXMLfile.open('e') ){

   myXMLfile.write(myXML);

   myXMLfile.close();

   app.activeDocument.metadataPreferences.append(myXMLfile);

   myXMLfile.remove();

}

var myDocXMP = app.activeDocument.metadataPreferences;

var destNamespace = "https://test.wordpress.com/";

var destNodeName = "MyTestingNode2";

var nodeValue = " test value";

myDocXMP.setProperty(destNamespace, destNodeName, nodeValue);

It seems to work on active document.


Reference :

Storing custom data into InDesign file via XMP | IndiSnip [InDesign® Snippets]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines