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

documentID to source?

Explorer ,
Jun 30, 2015 Jun 30, 2015

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.

TOPICS
Scripting
1.3K
Translate
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 ,
Jun 30, 2015 Jun 30, 2015

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
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
Enthusiast ,
Jul 02, 2015 Jul 02, 2015

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
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 06, 2015 Jul 06, 2015
LATEST

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

Translate
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
Enthusiast ,
Jul 01, 2015 Jul 01, 2015

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) { }

        }

    }

};

Translate
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