Using Guides commands in CS5 to find Guide Coordinates?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

LarsMarkelson

Using Guides commands in CS5 to find Guide Coordinates?

Post by LarsMarkelson »

I can't figure out how to use this Guide property in CS5.

I'm trying stuff like this,

alert(app.activeDocument.direction);

alert(app.activeDocument.guides.direction);

And am not getting any relevant info. I have two guides placed and can't get the info I want from them.

Also, if I had like 5 guides, how would I find their coordinates?

Here's the relevant info from the Scripting Guide (JSX);




Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

LarsMarkelson

Using Guides commands in CS5 to find Guide Coordinates?

Post by LarsMarkelson »

Code: Select allvar guides = app.activeDocument.guides;// get the current doc's guides
var guideArray = [];
for( var g = 0; g < guides.length; g++ ){
    guideArray.push( [guides[g].direction, guides[g].coordinate ]);// store the guide properties for later
}

alert(guideArray);

Found this VERY helpful code in another thread from Mike Hale. I added the alert part.

Quick question,

var guideArray = [];

Is that a JS shortcut for creating a new array? I thought the command was

var guideArray = new Array();
larsen67

Using Guides commands in CS5 to find Guide Coordinates?

Post by larsen67 »

Yes, its just shorthand…
LarsMarkelson

Using Guides commands in CS5 to find Guide Coordinates?

Post by LarsMarkelson »

Thanks! I appreciate the reply. Really noob question. Not that confident at googling answers right now, having a tough time chewing through some of the terminology on some sites.
Mike Hale

Using Guides commands in CS5 to find Guide Coordinates?

Post by Mike Hale »

var guideArray = []; is an implicit way to create an array.
var guideArray = new Array(); is the explicit way.
For the most part they do the same thing, but for some reason the explicit method is more often used with arrays. For numbers, implicit is more common. You don't often see var a = new Number(5); but it does about the same as var a = 5;
larsen67

Using Guides commands in CS5 to find Guide Coordinates?

Post by larsen67 »

The 'new' is also optional so in many cases you will also see…

Code: Select allvar guideArray = Array();