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
}
Use LowerCase names of colours. Additionally TypeUnits can't be in CM. startDisplayDialogs must be settled.
Copy link to clipboard
Copied
Use LowerCase names of colours. Additionally TypeUnits can't be in CM. startDisplayDialogs must be settled.
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.
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
Copy link to clipboard
Copied
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.
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 ð
Copy link to clipboard
Copied
This will stroke the canvas. Is there anyway for image layer alone?
Copy link to clipboard
Copied
Make selection of layer instead of selectAll() function.