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

How can I draw a rectangle?

Engaged ,
Jun 11, 2015 Jun 11, 2015

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
3.5K
Translate
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

...
Translate
Adobe
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]], 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;

};

};

Translate
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

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

Translate
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

Limited support for Shapes is one clear shortcoming of the Javascript API.. Reading & manipulating fill, stroke, etc. settings would be very nice.

Translate
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

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.

Translate
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

Which post are you referring to, Bazsl?

Never mind, found it.

Davide

Translate
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
LATEST
Translate
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

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

Translate
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

Yeah, I meant DOM.

Translate
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

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 …

Translate
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