Get details about guides

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

Moderators: xbytor, DavideBarranca, Paul MR

jacobolus

Get details about guides

Postby jacobolus » Mon Jun 25, 2012 9:29 am

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 all
var $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

Postby Mike Hale » Mon Jun 25, 2012 4:42 pm

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

Postby jacobolus » Mon Jun 25, 2012 6:30 pm

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

Postby Mike Hale » Tue Jun 26, 2012 5:25 pm

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

Postby jacobolus » Wed Jun 27, 2012 12:29 am

Code: Select all
var $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'
}


Return to “Photoshop Scripting: Code Snippets”

Who is online

Users browsing this forum: No registered users and 2 guests