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

Stroke Selected layer

Community Beginner ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Hi
I'm quite new with javascript for Photoshop. I'm writing script that will facilitate my work on files and one of the functions should stroke the active document (2 px stroke)(just like Edit->Stroke function in PS). The script must always stroke the entire open document. Not counting one line with the stroke function itself, everything works fine but does not outline, the script stops working immediately after selection.

Help me please

function ObrysWartswy(){
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO
var strokeColor = new SolidColor;
strokeColor.cmyk.Cyan = 0;
strokeColor.cmyk.Magenta = 0;
strokeColor.cmyk.Yellow = 0;
strokeColor.cmyk.Black = 100;
app.activeDocument.selection.selectAll();
app.activeDocument.selection.stroke(strokeColor, 2);
app.activeDocument.selection.deselect();
app.preferences.rulerUnits = Units.CM
app.preferences.typeUnits = TypeUnits.CM
app.displayDialogs = startDisplayDialogs
}

 

TOPICS
Actions and scripting , Windows

Views

1.7K

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

LEGEND , Jan 22, 2020 Jan 22, 2020

Use LowerCase names of colours. Additionally TypeUnits can't be in CM. startDisplayDialogs must be settled.

Votes

Translate

Translate
Adobe
LEGEND ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Use LowerCase names of colours. Additionally TypeUnits can't be in CM. startDisplayDialogs must be settled.

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 Beginner ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Thanks for the answer. To be honest, I have other functions in the script with this color notation and it works without a problem. In general, the whole script works just in centimeters due to other functions, only here I had to declare pixels for a moment so that the stroke would always have 2 pixels regardless of the size of the document. And what do you mean "startDisplayDialogs must be settled"?
This may be the reason for not working?
As I said earlier, the program stops on this line "app.activeDocument.selection.stroke (strokeColor, 2);" if I deactivates it, the script calmly performs the rest.

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
Guide ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

You really could use the custom names of colors in your functions in some situations - they are created as additional properties of the object and you can use them inside your code. However, when it comes to calling the DOM functions of Photoshop, you need to put the values into own properties of the SolidColor object, which writes from small letter

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
People's Champ ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

1. Use try { } catch(e) { }
2. strokeColor.cmyk is not set correctly. You have been given a reason. Javascript is case sensitive.
 

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
LEGEND ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

I believe you have other functions with the same colour notation, but as I said they must start from little letter. The script surely may work in CM, but for Type Units there are allowed only milimeters, pixels and points. If you want to restore display dialogs at end of script, declare that at beginning.

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 Beginner ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Thank a lot to all of you !!

Now I get it how it works ( or I think that I know 🙂 )

function ObrysWartswy(){
	app.preferences.rulerUnits = Units.PIXELS
	var strokeColor = new SolidColor;
	strokeColor.cmyk.cyan = 0;
	strokeColor.cmyk.magenta = 0;
	strokeColor.cmyk.yellow = 0;
	strokeColor.cmyk.black = 100;	
	app.activeDocument.selection.selectAll();
	app.activeDocument.selection.stroke(strokeColor, 2, StrokeLocation.INSIDE);
	app.activeDocument.selection.deselect();
	app.preferences.rulerUnits = Units.CM
	}

 

All works fine with that updated 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
Explorer ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

This will stroke the canvas. Is there anyway for image layer alone?

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
LEGEND ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

LATEST

Make selection of layer instead of selectAll() function.

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