Skip to main content
Participant
Jun 30, 2015 6:13 PM UTC
Question

documentID to source?

I tried to modify a script to copy the <xmpMM:DocumentID> to the <photoshop:TransmissionReference>, obviously I have had no luck. Where do I find the correct syntax for calling up the two fields?

#target bridge
if( BridgeTalk.appName == "bridge" ) {  
DocumentIDToSource= MenuElement.create("command", "Document ID to Source", "at the end of Tools");
}
DocumentIDToSource.onSelect = function () { 
var sels = app.document.selections;
for(var a in sels){
md =sels.synchronousMetadata; 
md.namespace = "http://ns.adobe.com/photoshop/1.0/";  
var DocumentID =  md.DocumentID.toString().replace(/,/g,'.');// Replace a comma with decimal point
md.namespace = "http://purl.org/dc/elements/1.1/"; 
md.TransmissionReference='';
md.TransmissionReference = DocumentID;
}
};

Any suggestions will be appreciated.

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Pedro Cortez Marques
Legend
Jul 1, 2015 6:17 PM UTC

You have to modify the namespaces and the exact property names for you purpose, but this can easily be adapted for your purpose:

Hope it helps.


#target bridge

if( BridgeTalk.appName == "bridge" ) {

DocumentIDToSource= MenuElement.create("command", "Document ID to Source", "at the end of Tools");

}

DocumentIDToSource.onSelect = function () {

    loadXMPLib();

    //

    var sels = app.document.selections;

    for(var a in sels){

        if (sels.spec instanceof File && sels.name.match(/\.(cr2|raw|dng|nef)$/i)) {

            var xmp = new XMPMeta(sels.synchronousMetadata.serialize());

            // try another namespace to get other simple properties:

            var DocumentID =  xmp.getProperty("http://ns.adobe.com/xap/1.0/mm/", "DocumentID");

            // If you are getting "localized text properties", use instead this one:

            // var Description =  xmp.getArrayItem("http://purl.org/dc/elements/1.1/", "description",1);

            // settting localized text property

            xmp.setLocalizedText("http://purl.org/dc/elements/1.1/", "TransmissionReference", null, "x-default", DocumentID);

            // setting simple property

            // xmp.setProperty("http://purl.org/dc/elements/1.1/", "NewProp", "my prop value");

            //

            var updatedPacket = xmp.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);

            sels.metadata = new Metadata(updatedPacket);

        }

    }

    //

    unloadXMPLib();

    // Functions needed:

    ///////////////////////////////

    function loadXMPLib() {

        if ( xmpLib == undefined ) {

              if( Folder.fs == "Windows" ) {

                  var pathToLib = Folder.startup.fsName + "/AdobeXMPScript.dll";

              } else {

                  var pathToLib = Folder.startup.fsName + "/AdobeXMPScript.framework";

              }

              var libfile = new File( pathToLib );

              var xmpLib = new ExternalObject("lib:" + pathToLib );

        }

    }

    ///////////////////////////////

    function unloadXMPLib() {

        if ( ExternalObject.AdobeXMPScript ) {

            try {

                ExternalObject.AdobeXMPScript.unload();

                ExternalObject.AdobeXMPScript = undefined;

            }catch (e) { }

        }

    }

};

Participant
Jun 30, 2015 6:16 PM UTC

I do know the purl namespace will have to be changed to something else—I left it there as a placeholder for when I have the right information...

Translate
Inspiring
Jul 2, 2015 8:10 AM UTC

To find the information for the different fields look at the Raw Data in the files File Info.

As an example:

        xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
     <photoshop:ColorMode>3</photoshop:ColorMode>
     <photoshop:ICCProfile>sRGB IEC61966-2.1</photoshop:ICCProfile>
     <photoshop:TransmissionReference>xmp.did:B68E7606EB18E5119A83DC86D4E48975</photoshop:TransmissionReference>
  </rdf:Description>
  <rdf:Description rdf:about=""
        xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
        xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#">
     <xmpMM:InstanceID>xmp.iid:FADF66149020E511B464E0DEE80B5EE4</xmpMM:InstanceID>
     <xmpMM:DocumentID>xmp.did:B68E7606EB18E5119A83DC86D4E48975</xmpMM:DocumentID>
     <xmpMM:OriginalDocumentID>xmp.did:B68E7606EB18E5119A83DC86D4E48975</xmpMM:OriginalDocumentID>
     <xmpMM:History>

You can see that TransmissionReference is part of the Photoshop namespace and DocumentID is is part of xmpMM namespace

so your code would be.

#target bridge   

    if( BridgeTalk.appName == "bridge" ) { 

    DocumentIDToSource= MenuElement.create("command", "Document ID to Source", "at the end of Tools");

    }

    DocumentIDToSource.onSelect = function () { 

var sels = app.document.selections;

    for(var a in sels){

    md =sels.synchronousMetadata;

md.namespace = "http://ns.adobe.com/xap/1.0/mm/";

    var DocumentID =  md.DocumentID.toString().replace(/,/g,'.');// Replace a comma with decimal point

    md.namespace = "http://ns.adobe.com/photoshop/1.0/"; 

    md.TransmissionReference='';

    md.TransmissionReference = DocumentID;

    }

Translate
Participant
Jul 6, 2015 3:36 PM UTC

Thanks! I will try this—I have been away for a long weekend.

Translate