Get details about guides

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

jacobolus

Get details about guides

Post by jacobolus »

For what it’s worth, since CS5, it’s also possible to get the number of guides this way using Action Manager code:

Code: Select allvar $s = function (s) { return app.stringIDToTypeID(s); };
var num_guides_ref = new ActionReference;
num_guides_ref.putProperty($s('property'), $s('numberOfGuides'));
num_guides_ref.putEnumerated($s('document'), $s('ordinal'), $s('targetEnum'));
var num_guides = app.executeActionGet(num_guides_ref).getInteger($s('numberOfGuides'));

And it’s possible to get the guides by index inside the current document. What’s kind of odd about this is that 'numberOfGuides' doesn’t actually show up in the document descriptor. To get access, you have to ask for it explicitly like this. Yet another weird inconsistency. :/
Mike Hale

Get details about guides

Post by Mike Hale »

I think this is incredibly interesting. I would have said( and did so in a recent post ) that if it's not in the descriptor, you can't get it. Clearly you have shown that is not the case. One question to ask is can this be applied to other things like selection?

Do you see any advantage to using Action Manager to access guides? It seems to me that, unlike layers, there is no advantage to AM and it uses more lines and is harder to read than using the DOM.
jacobolus

Get details about guides

Post by jacobolus »

No particular advantage. I just found it curious, and so thought it was worth mentioning. Might be slightly faster because it doesn't require fetching the "document" object from the DOM.
Mike Hale

Get details about guides

Post by Mike Hale »

jacobolus wrote:And it’s possible to get the guides by index inside the current document.

With Action Manager? Can you post an example?
jacobolus

Get details about guides

Post by jacobolus »

Code: Select allvar $s, guide_ref, guide_desc;
$s = function (s) { return app.stringIDToTypeID(s); };

// ref to 1st guide of current document
guide_ref = new ActionReference;
guide_ref.putIndex($s('guide'), 1);
guide_ref.putEnumerated($s('document'), $s('ordinal'), $s('targetEnum'));

guide_desc = app.executeActionGet(ref)


The resulting guide descriptor has content like:
Code: Select all$desc 'guide', {
    itemIndex: $int 1
    count: $int 1
    position: $unit 'pixelsUnit', 780
    orientation: $enum 'orientation.horizontal'
}