Skip to main content
Pedro Cortez Marques
Legend
October 8, 2012
Answered

Sort by CR2s AND camera

  • October 8, 2012
  • 9 replies
  • 2715 views

I want to sort images by 2 rules:

1- after salect only the CR2 images

2- sort them all by the camera that took those shots

Generally I have a group of CR2 shots from 2 cameras

Is this possíble also to apply this as the default sort of bridge?

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Paul Riggott

Thanks Paul!

Take your time.

I'm glad you gave me a hope.


Could you please try this code Pedro and see if it works...

//.BridgeSort format
#target bridge
if( BridgeTalk.appName == "bridge" ) { 
var sortCameras = new MenuElement( "command","Sort Cameras", "at the end of Tools" , "sortCameras" );
}
sortCameras.onSelect = function () {
var fileSort = new File(app.document.presentationPath +"/.BridgeSort");
if(fileSort.exists) fileSort.remove();
var fileList=[];
app.document.deselectAll();
var items = app.document.getSelection ("cr2,crw");
for (var a in items){
if(items.type != "file") continue;
var md = items
.synchronousMetadata;
md.namespace = "
http://ns.adobe.com/exif/1.0/aux/";
var Serial = md.SerialNumber.toString();
fD = File(items.spec).created;
var FileDate = fD.getFullYear() + (fD.getMonth() +1).toString();
FileDate += (zeroPad(fD.getDate(),2).toString()) +  (zeroPad(fD.getHours(),2).toString());
FileDate += (zeroPad(fD.getMinutes(),2).toString()) + (zeroPad(fD.getSeconds(),2).toString());
fileList.push([[items
.name],[Serial],[FileDate]]);
}
fileList.sort();
fileList.sort(function(a,b){return a[1]-b[1];}).reverse();
app.document.sorts = [{ type:"string",name:"name", reverse:false }];
fileSort.open("w", "TEXT", "????");
$.os.search(/windows/i)  != -1 ? fileSort.lineFeed = 'windows'  : fileSort.lineFeed = 'macintosh';
fileSort.encoding = "UTF-8";
fileSort.writeln("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>");
fileSort.writeln("<dirinfo>");
fileSort.writeln("<files>");
for(var t in fileList){
    fileSort.writeln("<item key='" +fileList[0].toString() +fileList[2].toString() +"' />");
    }
fileSort.writeln("</files>");
fileSort.writeln("</dirinfo>");
fileSort.close();
fileSort.hidden=true;
app.document.chooseMenuItem("mondo/command/new");
app.documents[0].close();
app.document.sorts = [{ name:"user",type:"date", reverse:false }];

function zeroPad(n, s) {
   n = n.toString();
   while (n.length < s)  n = '0' + n;
   return n;
};
};


Paul Riggott
Inspiring
October 8, 2012

I would love to know how to do a custom sort!

One way would be to create Collections for each camera....

#target bridge

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

var groupCameras = new MenuElement( "command","Group Cameras", "at the end of Tools" , "groupCameras" );

}

groupCameras.onSelect = function () {

var items = app.document.getSelection ("cr2");

Cameras=[];

for (var a in items){

if(items.type != "file") continue;

var md = items.synchronousMetadata;

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

var Serial = md.SerialNumber.toString();

if(Serial != '') Cameras.push(Serial);

}

Cameras = ReturnUniqueSortedList(Cameras).sort();

for(var x in Cameras){

var foundFiles = app.createCollection(Cameras);

for (var a in items){

if(items.type != "file") continue;

var md = items.synchronousMetadata;

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

if(Cameras == md.SerialNumber.toString()){

    app.addCollectionMember(foundFiles,items);

    }

    }

}

function ReturnUniqueSortedList(ArrayName){

var unduped = new Object;

for (var i = 0; i < ArrayName.length; i++) {  

unduped[ArrayName] = ArrayName;

}

var uniques = new Array;

for (var k in unduped) {

   uniques.push(unduped);

   }

return uniques.sort();

}

}


Pedro Cortez Marques
Legend
October 9, 2012

Hi Paul... and thanks.

I found on this post (and it works) that it is possible to save a pre-defined sort as manual sort.

Your good work.

http://forums.adobe.com/message/4748987#4748987#4748987

Then it could be retreived any time as needed.

Do you think is possible to combine your code with this one? Am I asking too much?

Then, I will put it on an snp window on a button to call it from bridge left column.

Message was edited by: Pedro Marques

Paul Riggott
Inspiring
October 9, 2012

Unfortunately not at the moment, I will have to look at the format of  the hidden .BridgeSort file, but it might be a way of doing a custom sort!

I will have a look and see if it is possible though Pedro, it is a good idea!