Skip to main content
showshow
Inspiring
September 23, 2016
Answered

Script function of focal lenght metadata

  • September 23, 2016
  • 2 replies
  • 1415 views

Hello everybody,

I am looking to apply a script on my pictures, wich one is able to recognize the focal lenght in the metadatas.

I've made a specific series of photo with 3 focal lenght: 50mm;70mm and 105 mm and i wish apply a specific script on my pictures in function of the focal lenght...

I hope you can help me

Best regards

This topic has been closed for replies.
Correct answer SuperMerlin

Amend the ActionName and ActionSet to suit.

#target photoshop

if(documents.length){

if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

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

if( xmp.doesPropertyExist("http://ns.adobe.com/exif/1.0/", "FocalLength" ) ){

var fl= xmp.getProperty(XMPConst.NS_EXIF, "FocalLength").toString().match(/^\d+/);

switch(Number(fl)){

    case  50 : doAction("ActionName","ActionSet"); break;

    case 70 : doAction("ActionName","ActionSet"); break;

    case 105 : doAction("ActionName","ActionSet"); break;

    default : doAction("ActionName","ActionSet"); //any other focal length

    }

}else{

    //No Focal Length

    doAction("ActionName","ActionSet");

    }

};

2 replies

showshow
showshowAuthor
Inspiring
October 7, 2016

Hello Merlin Super

If i want to,now, treat pictures from a specific camera (use serial number modele)

do i proceed like this...

if(documents.length){ 

if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript"); 

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

if( xmp.doesPropertyExist("http://ns.adobe.com/exif/1.0/", "SerialNumber" ) ){ 

var fl= xmp.getProperty(XMPConst.NS_EXIF, "SerialNumber").toString().match(/^\d+/); 

switch(Number(fl)){ ..... etc

I guess iam wrong cause that is not working like i wish...

SuperMerlin
Inspiring
October 7, 2016

Very close!

if(documents.length){

if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

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

if( xmp.doesPropertyExist(XMPConst.NS_EXIF_AUX, "SerialNumber" ) ){

var sn= xmp.getProperty(XMPConst.NS_EXIF_AUX, "SerialNumber");

switch(Number(sn)){

    case 2131204425 : doAction("ActionName","ActionSet"); break; 

    case 3421222270 : doAction("ActionName","ActionSet"); break; 

    case 6777745321 : doAction("ActionName","ActionSet"); break; 

    default : doAction("ActionName","ActionSet"); //any other camera number

    }

}else{

        //no serial

        doAction("ActionName","ActionSet");

        }

}

showshow
showshowAuthor
Inspiring
October 7, 2016

I am getting closer; thx Supa Merlin

SuperMerlin
SuperMerlinCorrect answer
Inspiring
September 23, 2016

Amend the ActionName and ActionSet to suit.

#target photoshop

if(documents.length){

if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

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

if( xmp.doesPropertyExist("http://ns.adobe.com/exif/1.0/", "FocalLength" ) ){

var fl= xmp.getProperty(XMPConst.NS_EXIF, "FocalLength").toString().match(/^\d+/);

switch(Number(fl)){

    case  50 : doAction("ActionName","ActionSet"); break;

    case 70 : doAction("ActionName","ActionSet"); break;

    case 105 : doAction("ActionName","ActionSet"); break;

    default : doAction("ActionName","ActionSet"); //any other focal length

    }

}else{

    //No Focal Length

    doAction("ActionName","ActionSet");

    }

};

showshow
showshowAuthor
Inspiring
September 23, 2016

Thank you again...

superMerlin