Stdlib.getObjectProperty

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

xbytor

Stdlib.getObjectProperty

Post by xbytor »

I added a function called Stdlib.getObjectProperty awhile back and have just committed some changes to sourceforge that improve its usefulness immensely.

getObjectProperty is a function that simplifies accessing properties that are normally only available via the Action Manager APIs.

The syntax is

Stdlib.getObjectProperty(obj, propSym);

where obj is a Document, Application, or a Layer/LayerSet object. The function returns the value of the appropriate type (number, string, boolean, ActionDescriptor (for objects)).

This means you can do stuff like this:

Code: Select all    var bool = Stdlib.getObjectProperty(doc.activeLayer, "Vsbl", "Lyr ")
    var str = Stdlib.getObjectProperty(doc, 'Ttl ');
    var file = Stdlib.getObjectProperty(app, 'Path');
    var clrDesc = Stdlib.getObjectProperty(app, 'FrgC');


There is also a slightly different syntax:

Stdlib.getObjectProperty(index, propSym, objSym);

Where index is the index of the object and objSym is its type id symbol. As of this moment, this interface only works for Layers/LayerSets. And the usage looks like this:

Code: Select all    var str = Stdlib.getObjectProperty(1, "Nm  ", "Lyr ")

This gets the name of the layer that has an index of 1.

Let me know if this makes things any easier or if I'm just solving a problem that doesn't really exist.


-X
xbytor

Stdlib.getObjectProperty

Post by xbytor »

Actually, I probably should just add this function:

Code: Select allStdlib.getLayerProperty = function(layerIndex, propSym) {
   return Stdlib.getObjectProperty(layerIndex, propSym, 'Lyr ');
}

for get layer properties by index...

-X
Mike Hale

Stdlib.getObjectProperty

Post by Mike Hale »

Do these functions also work with stringIDs?

Mike
xbytor

Stdlib.getObjectProperty

Post by xbytor »

These functions work with charIDs (e.g. 'Nm '), stringIDs (e.g. 'backgroundColor'), and typeIDs (e.g. 1164338787).


BTW, I couldn't figure out a way to get values using document's index.

-X
Mike Hale

Stdlib.getObjectProperty

Post by Mike Hale »

xbytor wrote:BTW, I couldn't figure out a way to get values using document's index.

My notes are at home, but I seem to remember that when working with docs you need to use the offset to the itemIndex of the current activeDoc

Code: Select alldesc.putOffset( charIDToTypeID( "Dcmn" ), -1 );

Eidt: I just tried using putIndex and it works for me

Code: Select all   var ref = new ActionReference();
   ref.putIndex( charIDToTypeID( "Dcmn" ), 1 );
   var desc = executeActionGet(ref);
Mike Hale

Stdlib.getObjectProperty

Post by Mike Hale »

I did a CVS checkout of xtools last week and now getterdemo is not working for me.

Here is a quick and dirty version for checking keys in a descriptor.

Code: Select allfunction getDocumenetDescByItemIndex(idx){
   var ref = new ActionReference();
   ref.putIndex( charIDToTypeID( "Dcmn" ), idx );
   return executeActionGet(ref)
}
//get a descriptor in this example a doc
var desc = getDocumenetDescByItemIndex(1);
//list the stringID of the keys in the descriptor
for(var i = 0;i<desc.count;i++){
$.writeln(typeIDToStringID(desc.getKey(i)));
}
xbytor

Stdlib.getObjectProperty

Post by xbytor »

Mike Hale wrote:I did a CVS checkout of xtools last week and now getterdemo is not working for me.

I just did a refresh out to sourceforge. If this doesn't fix the problem, I'll probably need the document you were running Getter on to get the problem debugged.

Here is a quick and dirty version for checking keys in a descriptor.

I was testing with and index of 0...

I'll be adding this to stdlib.js

Code: Select allStdlib.getDocumentProperty = function(index, propSym) {
  return Stdlib.getObjectProperty(index, propSym, 'Dcmn');
};


-X
Mike Hale

Stdlib.getObjectProperty

Post by Mike Hale »

It could be that there is something else going on, however it doesn't work now with any doc.

If I create a new RGB doc then run getterdemo from ESTK the dialog opens in Photoshop. If I clear all the checkboxes then check layer and click on process ESTK throws a 'undefined is not an object' at the try block of win.process.onClick.

The doc doesn't seem to matter so If it's working for you I'll try to track down what's wrong with my install.

Thanks,
Mike
xbytor

Stdlib.getObjectProperty

Post by xbytor »

If you run it under ESTK, you need to turn off "Don't Break On Guarded Exceptions".

I'll fix it so this isn't a problem in the future.

-X
xbytor

Stdlib.getObjectProperty

Post by xbytor »

Actually, there are several places where exceptions are expected in Getter/Demo. I may not be handling them all transparently.

-X