Hi, so I have been writing a sprite creator script. One of the things I would like this script to do is get the bounds of layers and groups automatically. I have been using this to get the layer bounds (both vector mask layers and bitmapped layers)
Code: Select all getBoundsByIndex: function(idx) {
var ref = new ActionReference();
ref.putProperty( cTID("Prpr") , sTID( "bounds" ));
ref.putIndex( cTID( "Lyr " ), idx );
var desc = executeActionGet(ref).getObjectValue(sTID( "bounds" ));
var bounds = [];// array of Numbers as pixels regardless of ruler
bounds.push(desc.getUnitDoubleValue(sTID('left')));
bounds.push(desc.getUnitDoubleValue(sTID('top')));
bounds.push(desc.getUnitDoubleValue(sTID('right')));
bounds.push(desc.getUnitDoubleValue(sTID('bottom')));
return bounds;
}
It works well. What I want to do is use something similar to get the bounds of a specified layer group. This code does not work for that situation. I guess I could go through each item in the group and evaluate each's bounds as an aggregate. Before I go about doing that, I thought I would throw this out here to see if anyone has any better options.
Thanks
rp
Get bounds of a group
Get bounds of a group
This seems to be a case where you can do something with the DOM that you can't do as easy with action manager.
Code: Select allapp.activeDocument.layerSets[0].bounds;
Does return the correct bounds for all the nested layers.
Code: Select allapp.activeDocument.layerSets[0].bounds;
Does return the correct bounds for all the nested layers.
Get bounds of a group
Thanks Mike,
it looks like you're right. Unfortunately photoshop gets confused about the actual size of the "content" in a layer group if it includes an adjustment layer or a layer that acts as a clipping mask. Seems like the best way to do this is to just go through all the layers in the group and determine if its bounds are worthy to be considered part of the actual content.
By the way, is there some api documentation were we can find the meaning to the charID's and what types of Descriptors and References they apply to?
it looks like you're right. Unfortunately photoshop gets confused about the actual size of the "content" in a layer group if it includes an adjustment layer or a layer that acts as a clipping mask. Seems like the best way to do this is to just go through all the layers in the group and determine if its bounds are worthy to be considered part of the actual content.
By the way, is there some api documentation were we can find the meaning to the charID's and what types of Descriptors and References they apply to?
Get bounds of a group
I notice that the C++ API has a header file PIStringTerminology.h that lists the definitions of constant strings that get used.
I cant seem to glean that much helpful information from it though.
I cant seem to glean that much helpful information from it though.
Get bounds of a group
If there is an official documentation on charID it's in that header file in the Photoshop SDK. And you are right, it's not that helpful. You can get a somewhat more meaningful string by converting the charID to stringID. But even then some IDs mean different things depending on how they are used( class,event,key,type, or enum).
I think most of us don't worry about it too much as long as it works.
An adjustment layer's bounds(if it doesn't have a mask) will be the same a the document bounds wither it's inside a group or not. And the bounds of a layer in a clipping group doesn''t change because they are clipped even in the GUI.
I think most of us don't worry about it too much as long as it works.
An adjustment layer's bounds(if it doesn't have a mask) will be the same a the document bounds wither it's inside a group or not. And the bounds of a layer in a clipping group doesn''t change because they are clipped even in the GUI.