Copy link to clipboard
Copied
I looked around on the forums for this answer, but I couldn't find anything specific.
I would like to be able to use the marquee tool to define an area and then create an action where guidelines will be placed against the marquee selection. I may be overthinking this, but is this even possible?
Thanks.
Copy link to clipboard
Copied
Shan-Dysigns​
Hmmh?
I do not have an action for you but you can try a script snippet:
// regards pixxxel schubser
var aDoc = activeDocument;
var Sel = aDoc.selection.bounds;
aDoc.guides.add(Direction.VERTICAL, Sel[0].as('px'));
aDoc.guides.add(Direction.HORIZONTAL, Sel[1].as('px'));
aDoc.guides.add(Direction.VERTICAL, Sel[2].as('px'));
aDoc.guides.add(Direction.HORIZONTAL, Sel[3].as('px'));
Have fun
Copy link to clipboard
Copied
I create a blank document, use the marquee tool to draw a selection, enact the script, and receive this error.
Copy link to clipboard
Copied
What are your ruler units set to? That script should set the ruler to get the selection bounds in pixels. It does not
// regards pixxxel schubser
var orig_ruler_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS
var aDoc = activeDocument;
var Sel = aDoc.selection.bounds;
aDoc.guides.add(Direction.VERTICAL, Sel[0].as('px'));
aDoc.guides.add(Direction.HORIZONTAL, Sel[1].as('px'));
aDoc.guides.add(Direction.VERTICAL, Sel[2].as('px'));
aDoc.guides.add(Direction.HORIZONTAL, Sel[3].as('px'));
app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings
Copy link to clipboard
Copied
Ruler units were px when I tested the script. I'm pretty advanced in javascript/jQuery (web development), but I wish I had the time to experiment in Photoshop.
Copy link to clipboard
Copied
Shan-Dysigns wrote
Ruler units were px when I tested the script. I'm pretty advanced in javascript/jQuery (web development), but I wish I had the time to experiment in Photoshop.
What seem strange is you are getting a error on line 13. that statement was line 6 in the first script and line 7 in the second script neither scripts had 13 lines the were shorter. Please post the script your using...
Copy link to clipboard
Copied
I can not make it fail no matter what selection I create it sets guides for the selections bounds. Wait are you using CS2 if I remember selection bounds was broken in cs2?
It does fail in CS2 but with a different error than you get What version of Photoshop are you using?
Copy link to clipboard
Copied
I am still using CS4, so maybe the issue carried over from CS2.
Copy link to clipboard
Copied
Post the script your using something is strange.
Copy link to clipboard
Copied
My notifications must be turned off. I just happened to catch your reply today.
The script I am using is the one supplied above from pixxxel schubser.
​When I tried the script you provided, I received the same error.
Copy link to clipboard
Copied
If you set ruler units to pixels, there is no need to do the same in the code again.
// regards pixxxel schubser
var orig_ruler_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS
var aDoc = activeDocument;
var Sel = aDoc.selection.bounds;
aDoc.guides.add(Direction.VERTICAL, Sel[0]);
aDoc.guides.add(Direction.HORIZONTAL, Sel[1]);
aDoc.guides.add(Direction.VERTICAL, Sel[2]);
aDoc.guides.add(Direction.HORIZONTAL, Sel[3]);
app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings
Have fun
Btw
If I remember right, this will work correct in CS5 and later.
Copy link to clipboard
Copied
Untested but should work in CS2 or newer so long as a selection has been made.
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var bnds = getSelectionBounds();
guideLine(bnds[1],"Hrzn",'#Pxl');
guideLine(bnds[3],"Hrzn",'#Pxl');
guideLine(bnds[0],"Vrtc",'#Pxl');
guideLine(bnds[2],"Vrtc",'#Pxl');
preferences.rulerUnits = startRulerUnits;
function guideLine(position, type,unit) {
//units '#Pxl' pixel '#Rlt' =Relatiive '#Prc' = percent
// types: 'Vrtc' & 'Hrzn'
var desc = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Pstn'), charIDToTypeID(unit), position);
desc2.putEnumerated( charIDToTypeID('Ornt'), charIDToTypeID('Ornt'), charIDToTypeID(type) );
desc.putObject( charIDToTypeID('Nw '), charIDToTypeID('Gd '), desc2 );
executeAction( charIDToTypeID('Mk '), desc, DialogModes.NO );
};
function getSelectionBounds() {
var doc = activeDocument;
var l = doc.artLayers.add();
doc.selection.fill(app.foregroundColor);
var bnds = l.bounds;
var hs = doc.historyStates;
if (hs[hs.length-2].name == "Layer Order") {
doc.activeHistoryState = hs[hs.length-4];
} else {
doc.activeHistoryState = hs[hs.length-3];
}
for (var i = 0; i < bnds.length; i++) {
bnds = bnds.value;
}
return bnds;
};
Copy link to clipboard
Copied
Selection Bounds does not work in CS2 I had to code around that bug in CS2
Copy link to clipboard
Copied
I am not using selection bounds, I am using Layer bounds and that does work in CS2.
Copy link to clipboard
Copied
I did not look at the code I just read the function name Using Layer bounds is how I coded around the selection bounds bug in cs2.
Copy link to clipboard
Copied
My email notifications must be turned off because I just now noticed your reply.
Your code worked. I know javascript, but not enough when it comes to Photoshop, so I can somewhat understand the code, but not necessarily what makes it work. The code worked in all the ways I would try to apply it, so thanks for providing it.