What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Reply to thread

Hi Ian, just had a quick play, you will need to tidy the code up but this seems to get the names and IDs of all layers.

Best of luck!

[code]

#target photoshop;

function main() {

file = File.openDialog("Please select PSD file.","PSD File:*.psd");

  if(!file.exists) return;

  file.open("r");

  file.encoding = 'BINARY';

  var dat = file.read();

  file.close();

 

  var result;

  var pos =[];

  var Text= [];

    var IDs = [];

  var rex = /8BIMluni/g;

 

  while ((result = rex.exec(dat)) != null) { // Find ALL occurencies of search string

  //   $.writeln(result.index+(result[0].length));

    //$.writeln(result.index); //Index of regex found

    //  alert(result[0].length); //Length of string found

    pos.push(result.index+(result[0].length));

  }

    var rex2 = new RegExp ('8BIMlyid','g');

  while ((result = rex2.exec(dat)) != null) { // Find ALL occurencies of search string

    //$.writeln(result.index); //Index of regex found

   IDs.push( readWord(dat, result.index + 12));

   }

  function readByte(str, ofs) {

    return str.charCodeAt(ofs);

  }

  function readInt16(str, ofs) {

    return (readByte(str, ofs) << 8) + readByte(str, ofs+1);

  }

  function readWord(str, ofs) {

    return (readInt16(str, ofs) << 16) + readInt16(str, ofs+2);

  }

  function readUnicodeChar(str, ofs) {

    return String.fromCharCode(readInt16(str,  ofs));

  }

 

  for (var i = 0; i < pos.length; i++) { //loop through all finds

    var ofs = pos[i]; //offset of find

    var textLength = readWord(dat, (ofs+ 4));  //Read length of string at offset

    //alert(textLength);

    ofs += 8; //increment offset to suit

    var str = ''; //reset string to ''

 

    for (var j = 0; j < textLength; j++) { //loop through string

      str += readUnicodeChar(dat, ofs); // add char

      ofs += 2; //increment two bytes

    }

//if(!str.match(/<\/Layer group/)){ // end of a layer group

    Text.push(str); //Layer name found and stored

   // }

  }

var w = new Window('dialog',decodeURI(file.name));

w.lb1 = w.add('listbox',undefined,'Names');

w.lb1.preferredSize= [500,200];

w.bu1 = w.add('button',undefined, 'Exit');

w.bu1.preferredSize = [500,35];

w.bu1.onClick=function(){

    w.close(0);

    }

Text.reverse();

IDs.reverse();

for (var i=0,len=Text.length;i<len;i++) {

    w.lb1.add('item',  Text[i] + " ID = " + IDs[i]);

};

//alert(Text.length + " ---- "  + IDs.length);

w.show();

};

 

main();


[/code]


What is our favorite program/app? (Hint - it begins and ends with the letter P)
Back
Top