Skip to main content
Participating Frequently
January 22, 2020
Answered

Stroke Selected layer

  • January 22, 2020
  • 1 reply
  • 2295 views

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
}

 

This topic has been closed for replies.
Correct answer Kukurykus

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

1 reply

Kukurykus
KukurykusCorrect answer
Legend
January 22, 2020

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

Participating Frequently
January 22, 2020

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.

Legend
January 22, 2020

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