X's Getter 'undefined' output

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

undavide

X's Getter 'undefined' output

Post by undavide »

Hi,
I've been using from time to time the following code from XBytor:

Code: Select allfunction zTID( s ){
   if( s.length == 4 ) var res = charIDToTypeID( s );
   if( s.length > 4 ) var res = stringIDToTypeID( s );
   return res;
}

var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
var c = desc.count
for(var i=0;i<c;i++){ //enumerate descriptor's keys
  $.writeln('Key '+i+' = '+zTID(desc.getKey(i))+': '+desc.getType(desc.getKey(i)))
}


Now, it's been a while since last time I used it but running the above code in PS CS6 gives the following output:

Code: Select allKey 0 = undefined: DescValueType.STRINGTYPE
Key 1 = undefined: DescValueType.ENUMERATEDTYPE
Key 2 = undefined: DescValueType.BOOLEANTYPE
Key 3 = undefined: DescValueType.ENUMERATEDTYPE
Key 4 = undefined: DescValueType.INTEGERTYPE
Key 5 = undefined: DescValueType.INTEGERTYPE
Key 6 = undefined: DescValueType.INTEGERTYPE
Key 7 = undefined: DescValueType.INTEGERTYPE
Key 8 = undefined: DescValueType.BOOLEANTYPE
Key 9 = undefined: DescValueType.BOOLEANTYPE
Key 10 = undefined: DescValueType.INTEGERTYPE
Key 11 = undefined: DescValueType.BOOLEANTYPE
Key 12 = undefined: DescValueType.ENUMERATEDTYPE
Key 13 = undefined: DescValueType.OBJECTTYPE
Key 14 = undefined: DescValueType.BOOLEANTYPE
Key 15 = undefined: DescValueType.LISTTYPE
Key 16 = undefined: DescValueType.LISTTYPE
Key 17 = undefined: DescValueType.LISTTYPE
Key 18 = undefined: DescValueType.INTEGERTYPE
Key 19 = undefined: DescValueType.BOOLEANTYPE
Key 20 = undefined: DescValueType.BOOLEANTYPE
Key 21 = undefined: DescValueType.BOOLEANTYPE
Key 22 = undefined: DescValueType.INTEGERTYPE
Key 23 = undefined: DescValueType.DOUBLETYPE
Key 24 = undefined: DescValueType.INTEGERTYPE
Key 25 = undefined: DescValueType.DOUBLETYPE
Key 26 = undefined: DescValueType.OBJECTTYPE
Key 27 = undefined: DescValueType.BOOLEANTYPE
Result: undefined

I'm wondering why I'm getting these "undefined" all over - shouldn't they be something more descriptive, like

Code: Select allKey 5 = layerID: DescValueType.INTEGERTYPE

Thanks in advance for your help!

Davide

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

undavide

X's Getter 'undefined' output

Post by undavide »

For some reason I did save the getter with a wrong line...

Code: Select all  $.writeln('Key '+i+' = '+zTID(desc.getKey(i))+': '+desc.getType(desc.getKey(i)))

this one works as expected:

Code: Select all  $.writeln('Key '+i+' = '+app.typeIDToStringID(desc.getKey(i))+': '+desc.getType(desc.getKey(i)))

Davide
Mike Hale

X's Getter 'undefined' output

Post by Mike Hale »

That zTID function has lots of problems. Here is what I am using now.
Code: Select allvar ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref).getObjectValue(charIDToTypeID( "Lefx")).getObjectValue(charIDToTypeID("IrSh"));
$.writeln( desc );

if(desc.typename == 'ActionReference'){
   var c = desc.count;
   for(var i=0;i<c;i++){ //enumerate reference. use getForm() to determine which get method to use
     $.writeln('Key '+zeroPad( i+1, 2 )+' = '+desc.getReference(i).getIndex());
   }
}

if(desc.typename == 'ActionList'){
   var c = desc.count;
   for(var i=0;i<c;i++){ //enumerate list
     $.writeln('Key '+zeroPad( i+1, 2 )+' = '+desc.getType(i))
   }
}
if(desc.typename == 'ActionDescriptor'){
   var c = desc.count;
   for(var i=0;i<c;i++){ //enumerate descriptor's keys
     $.writeln('Key '+zeroPad( i+1, 2 )+' = '+IDTz(desc.getKey(i))+' : '+desc.getType(desc.getKey(i)))
   }
}
function IDTz(id){
   var isCharID = false;
   try {
      if( new String( id ).length == 10 ) {
         isCharID = true;
         var charID = '"'+typeIDToCharID( id )+'"';
         var stringID = '"'+typeIDToStringID( id )+'"';
         if( stringID.length <=2 ) {
            stringID = '  NA   ';
         }else{
            while( stringID.length < 25 ){
            stringID += ' ';
            }
         }
      }else{
         var charID = ' NA  ';
         var stringID = '"'+typeIDToStringID( id )+'"';
         while( stringID.length < 25 ){
            stringID += ' ';
         }
      }
   }catch(e){}
   return charID+' | '+stringID;
}
function zeroPad(num,pad) {
     var z = Math.pow(10,Number(pad))
     return num <= z ? ((Number( num) + z).toString().substr(1)): num
}
xbytor

X's Getter 'undefined' output

Post by xbytor »

Where is this coming from? I don't recall having ever written zTID.
undavide

X's Getter 'undefined' output

Post by undavide »

I'm no more a reliable source - I saved that in a file called "X getter.jsx" some time ago I can't recall where I did get it I'm quite sure it was either PS scripting forum or ps-scripts.
Apparently over the time I messed with the content since the code, as saved, was flawed - but I can't say where I pasted the zTID from...

Davide