Copy link to clipboard
Copied
I need to simulate drawing a rectangle with the Rectangle tool in a script. One way is to use the Script Listener and modify the code so I can pass the necessary variables. Is there a better solution? Thanks.
You can draw a rectangle as follows.
...#target photoshop;
app.bringToFront();
main();
function main(){
try{
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var Colour = new SolidColor;
Colour.rgb.hexValue = 'ff00ff';
app.documents.add();
activeDocument.selection.select([[10, 10], [494, 10], [494, 350], [10,350]], SelectionTyp
Copy link to clipboard
Copied
You can draw a rectangle as follows.
#target photoshop;
app.bringToFront();
main();
function main(){
try{
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var Colour = new SolidColor;
Colour.rgb.hexValue = 'ff00ff';
app.documents.add();
activeDocument.selection.select([[10, 10], [494, 10], [494, 350], [10,350]], SelectionType.REPLACE, 0, false);
activeDocument.selection.stroke (Colour, 4, StrokeLocation.INSIDE,ColorBlendMode.NORMAL,100);
activeDocument.selection.deselect();
}catch(e){}
finally{
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
};
};
Copy link to clipboard
Copied
Hi Bazsl‌,
I'm afraid there is no DOM way to access the Rectangle tool so Scripting Listener is the way, as far as I know.
(this if you're asking about the vector rectangle tool, otherwise Philip's solution works just fine)
Regards,
Davide Barranca
---
www.davidebarranca.com
www.cs-extensions.com
Copy link to clipboard
Copied
Limited support for Shapes is one clear shortcoming of the Javascript API.. Reading & manipulating fill, stroke, etc. settings would be very nice.
Copy link to clipboard
Copied
Thanks for all of the answers. I used the Script Listener since I want to reproduce what the rectangle tool does interactively. Unfortunately, the Script Listener code will not execute. See my other post.
Copy link to clipboard
Copied
Which post are you referring to, Bazsl?
Never mind, found it.
Davide
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Limited support for Shapes is one clear shortcoming of the Javascript API.
Can that not all be done with AM code?
Or did you mean the Photoshop DOM when you wrote "Javascript API"?
Copy link to clipboard
Copied
Yeah, I meant DOM.
Copy link to clipboard
Copied
No denying DOM code is "easier on the eye" but where it really gets frustrating is where properties/features are even off-limits to AM code …