• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can I draw a rectangle?

Engaged ,
Jun 11, 2015 Jun 11, 2015

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.

TOPICS
Actions and scripting

Views

2.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jun 11, 2015 Jun 11, 2015

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

...

Votes

Translate

Translate
Adobe
Enthusiast ,
Jun 11, 2015 Jun 11, 2015

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;

};

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 11, 2015 Jun 11, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 11, 2015 Jun 11, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 12, 2015 Jun 12, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 12, 2015 Jun 12, 2015

Copy link to clipboard

Copied

Which post are you referring to, Bazsl?

Never mind, found it.

Davide

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 12, 2015 Jun 12, 2015

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2015 Jun 11, 2015

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"?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 12, 2015 Jun 12, 2015

Copy link to clipboard

Copied

Yeah, I meant DOM.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 12, 2015 Jun 12, 2015

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 …

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines