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

Custom sort - Bridge

New Here ,
Mar 11, 2015 Mar 11, 2015

I have been trying to create a plugin for Adobe Bridge that allows me to sort images by specific information included in the file name (e.g. CTR_2001 Cat D7R_SN 1124.jpg where CTR is the code, Cat is the manufacturer and 2001 the year).

First I need to sort files by specific codeOrder[].

Then, files with the same codeOrder have to be sorted by manufacturerOrder[] and then year (newest to older).

So, the result should be something like this:

CTR_2010 Case...jpg

CTR_2008 Case...jpg

CTR_2012 Cat...jpg

CTR_2009 Cat...jpg

CTR_2011 Komatsu.jpg

Once that's done I'll add keywords to each photo, probably sort some photos manually and extract the data into a text file.

I'm a newbie at coding and apologize for any basic mistake. But could somebody please help me? the app.document.sort is not showing me the sorted thumbnails.


#target bridge 

var codeOrder = ["CPL","TAC","CTR","WLR","CLD","WDZ","SSL","MGR","MSC","WWG","SHV","DMX","HEX","MAT","MEX","DEX","SEX","ADT","RKT","CAB","TRN","DIR","BOR","LBK","ATC","RTC","HTC","CTC","CRD","CRT","CRN","CPT","CPV","ROV","TAR","ROL","CHH","CTO","ASP","PVR","ASD","PRO","ASM","CBP","CNQ","RDW","PVM","SAW","LGF","FLB","DEL","LGL","YDR","SKD","LGM","ENV","JCR","CCR","RCR","ICR","OCR","SCP","SNS","FDR","CNV","SCA","CTV","AGM","LGT","WIT","BED","CMT","TTI","TTT","TTS","CAC","TRA","DUQ","DUI","DUT","DUS","PLT","MXT","CPU","WTV","TKT","BMT","DDT","BKT","SST","VAC","FLT","SVR","RFV","UTT","RBT","CNT","CST","VAN","SAT","TOW","ROT","GTR","CCT","FBT","EMV","TRK","SUV","PUT","BUS","AUT","LBY","SDR","AST","DBT","JEP","SBT","BTR","HBY","BLK","OFT","LGR","BEL","END","SID","CSR","RFR","CPR","GTL","VNR","VAR","TKR","EQP","CAM","TRL","TFL","RTF","FKL","ELF","SCL","BML","MNL","FWD","AGT","MFD","TWD","UTL","LLS","COM","HEA","BAL","SWA","ADS","SED","CUL","DIS","PLW","HPB","SPR","NHE","SPE","BRE","TIL","HAC","MOW","FOR","HAM","HAY","HAR","COT","PTE","SBE","GRH","RCE","IRR","PSP","AGR","LAN","COW","LSE","DUM","UTE","SEW","ATV","SNO","BRM","SWP","CSD","RVE","RVU","GCT","BAR","TUG","MCV","MPB","MRQ","DRL","OFD","OFM","CMP","GEI","GEN","GEC","GEL","LTW","SGN","WEL","PMP","WTR","TNK","ATM","CNP","CNM","AIR","SUR","MNQ","PLM","RRQ","CON","HYH","PLH","IPQ","INT","DRM","AEX","CRM","ENG","ATE","SSA","ATT","MIC","MII","MIE","MIW","MIS","POS","POT","REA","RER","REC"];

var manufacturersOrder = [ "Advance", "Agco", "Agrifull", "Airman", "Allis-Chalmers", "American", "Antonio", "Arnes", "Autocar", "Badger", "Ballytrading", "Belarus", "Bell", "Bobcat", "Bolens", "Buhler", "Bws", "Case", "Cat", "Caterpillar", "Challenger", "Cheyan", "Claas", "Clark", "Co-Op Implements", "Cockshutt", "Columbia", "Daewoo", "David", "Deloupe", "Deutz", "Deutz-Fahr", "Dodge", "Doosan", "Eagle", "Ebro", "Ecoceane", "Elies", "Extec", "Farmall", "Farmtrac", "Featherlite", "Fendt", "Fiat", "Fontaine", "Ford", "Foton", "Freightliner", "Fuchs", "Geffs", "Gehl", "Genie", "Globe", "Gmc", "Gradall", "Grove", "Hamm", "Harley", "Heil", "Hitachi", "Hpsi", "Hurlimann", "Hypac", "Hyundai", "International", "Ir", "Ironwolf", "Iseki", "Isuzu", "Itm", "Jcb", "Jd", "Jinma", "Jlg", "Jlr", "John Deere", "Kawasaki", "Kinetic", "Kobelco", "Koehring", "Komatsu", "Kp", "Krebs", "Kubota", "Kuegt", "Lamborghini", "Landini", "Leeboy", "Liebherr", "Lift", "Linde", "Lode", "Lorain", "M-R-S", "Mack", "Manac", "Mantis", "Marmoter", "Massey", "Mccormick", "Mclaughlin", "Metso", "Midland", "Minneapolis", "Mitsubishi", "Morooka", "Mustang", "Nessie", "New Holland", "Nordberg", "Oliver", "Oshkoshh", "Ottawa", "Pacific", "Peterbilt", "Peterson", "Pettibone", "Powerscreen", "Promax", "Renault", "Roadtec", "Royal", "Same", "Schwitczer", "Shibaura", "Shuttelift", "Sial", "Steiger", "Sterling", "Superior", "Supertrac", "Talbert", "Terex", "Terramite", "Thurman", "Timbco", "Toyota", "Trackless", "Tremcar", "Trio", "Valmet", "Vermeer", "Versatile", "Vogele", "Volvo", "Wagner", "Walmart", "Western", "White", "Wirtgen", "Zennoh", "Zetor" ];

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

    if(!MenuElement.find("myMetaData")){

        var newMenu = new MenuElement( "menu", "Brochure Automation", "after Help", "myMetaData" );

    }

    var sortPhotos = new MenuElement( "command", "Sort Photos", "at the end of myMetaData" , "xx1D" );

    var extMetadata = new MenuElement( "command", "Extract Metadata", "at the end of myMetaData" , "xx2D" );

}

sortPhotos.onSelect = function(){

  

    var imgs = [];

    var inputs;

    var i, j, k;

    var img;

    var src;

  // app.document.visibleThumbnails

    var thumbs = app.document.getSelection("psd, jpg, png, tif, gif");

    for(thumb = 0; thumb < thumbs.length; thumb++){

        img = {

            name : decodeURI(thumbs[thumb].name),

            year : parseInt(decodeURI(thumbs[thumb].name.match(/(19\d{2})|(20\d{2})/))),

            categoryOrder : codeOrder.length,

            manufacturerOrder : manufacturersOrder.length

            };

      

       

        for( k = 0; k < codeOrder.length; k ++ ){

            if( img.name.indexOf( codeOrder ) >= 0 ){

                img.categoryOrder = k;

                break;

            }

        }

        for( k = 0; k < manufacturersOrder.length; k ++ ){

            if( img.name.indexOf( manufacturersOrder ) >= 0 ){

                img.manufacturerOrder = k;

                break;

            }

        }

        imgs.push(img);

    }

    imgs.sort( function( a, b ){

        if( a.categoryOrder - b.categoryOrder != 0 ){

            return a.categoryOrder - b.categoryOrder;

        }else{

            if( a.manufacturerOrder - b.manufacturerOrder != 0 ){

                return a.manufacturerOrder - b.manufacturerOrder;

            }else{

                return b.year - a.year;

            }

        }

    }); // ends imgs.sort(function)

/*------------------*/

    var fileSort = new File(app.document.presentationPath +"/.BridgeSort");

    if(fileSort.exists) fileSort.remove();

  

    var fileList=[];

    for(var f in imgs){

        var tmpFile = File(app.document.presentationPath + "/" + imgs.name.toString()); 

        if(!tmpFile.exists) continue; //Ignore files that do not exist, better to create an error file.

        FileDate= (File(tmpFile).created).toString();

         fileList.push([+[decodeURI(tmpFile.name)],[FileDate]]);

    }

   app.document.sorts = [{ type:"string",name:"name", reverse:false }];

    fileSort.open("w", "TEXT", "????");

    fileSort.lineFeed="Unix";

    fileSort.encoding = "UTF-8";

    fileSort.writeln("<dirinfo>");

    fileSort.writeln("<files>");

    for(var t in fileList){

      //  alert(fileList[0].toString().replace(/&/,"&") +fileList[1].toString());

        fileSort.writeln("<item key='" +fileList[0].toString().replace(/&/,"&") +fileList[1].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; 

    };

TOPICS
Scripting
679
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
New Here ,
Mar 13, 2015 Mar 13, 2015
LATEST

I believe I don't need to use app.document.sort since I already have my images sorted in fileList array.

What do I need to do now to load this images to the content pane?

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