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

Adding/Reading XMP Metadata in a psd file

Guest
Feb 13, 2011 Feb 13, 2011

Copy link to clipboard

Copied

Hi,

I'm having some troubles to understand how to add and read XMP metadata on a psd file. I followed the Panel developer guide tutorial, and try to look on the internet for some answers, but I'm still stuck ...

Here is the simple example I'm trying to make (using part of the code from the panel developer guide) :

/**

     The function loads the XMP Script Library.

     @returns True if the XMP Script Library was loaded successfully.

     @type Boolean

*/

function loadXMPLibrary(){

     if ( !ExternalObject.AdobeXMPScript ){

          try{

               ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

          }catch (e){

               alert("Can't load XMP Script Library");

               return false;

          }

     }

     return true;

}

/**

     The function unloads the XMP Script Library.

*/

function unloadXMPLibrary(){

     if( ExternalObject.AdobeXMPScript ) {

          try{

               ExternalObject.AdobeXMPScript.unload();

               ExternalObject.AdobeXMPScript = undefined;

          }catch (e){

               alert("Can't unload XMP Script Library");

          }

     }

}

/**

    Try to put a new property into the metadata

*/

if( app.activeDocument || !loadXMPLibrary()){

    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);

    xmp.setProperty( XMPConst.NS_EXIF, "myProperty", "test" );

    activeDocument.xmpMetadata.rawData = xmp.serialize();

    unloadXMPLibrary();

    Window.alert(activeDocument.xmpMetadata.rawData);

}

I don't really know where I'm wrong, could you help me please ?

Thanks,

Julien

TOPICS
Actions and scripting

Views

5.8K
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
Adobe
Guru ,
Feb 13, 2011 Feb 13, 2011

Copy link to clipboard

Copied

Document.xmpMetadata is read only. You can edit some metadata using Document.info. Otherwise you have to edit/add the metadata while the file is not open in Photoshop.

Votes

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
Guest
Feb 13, 2011 Feb 13, 2011

Copy link to clipboard

Copied

If I use the appendArrayItem, it seems to work :

if( app.activeDocument || !loadXMPLibrary()){

    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);

    xmp.appendArrayItem(XMPConst.NS_DC, "myProperty", "test", 0,XMPConst.ARRAY_IS_ORDERED)

    activeDocument.xmpMetadata.rawData = xmp.serialize();

    unloadXMPLibrary();

    Window.alert(activeDocument.xmpMetadata.rawData);

}

To be more specific, I would be able to add a XML structure into the XMP metadata of the psd file, and be able to retrieve it "easily". Is it possible ?

Thanks,

Julien

Votes

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
Valorous Hero ,
Feb 13, 2011 Feb 13, 2011

Copy link to clipboard

Copied

LATEST

Rather mess with EXIF and Dublin Core namespaces, wouldn't it be better to create your own?

IE:


#target photoshop
addtoMeta();

function addtoMeta(){
if(!documents.length) return;
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData);
var myNamespace = "http://my.fantastic.newspace/";
var myPrefix = "nsfns:";
XMPMeta.registerNamespace(myNamespace, myPrefix);
xmp.setProperty(myNamespace, "myProperty", "A Test String");
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}

Votes

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