Page 2 of 2

Get details about guides

Posted: Mon Jun 25, 2012 9:29 am
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. :/

Get details about guides

Posted: Mon Jun 25, 2012 4:42 pm
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.

Get details about guides

Posted: Mon Jun 25, 2012 6:30 pm
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.

Get details about guides

Posted: Tue Jun 26, 2012 5:25 pm
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?

Get details about guides

Posted: Wed Jun 27, 2012 12:29 am
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'
}