Highlighted

Internal error when drawing a stroke on a selection

Community Beginner ,
Nov 15, 2020

Copy link to clipboard

Copied

I am trying to write a script to add a frame to my photos.  I am running into "internal errors".  I want to expand the canvas size, create a new layer, select all of the new layer, and use selection.stroke to draw a rectangle that fills the added space with a color.  I am getting the internal error when I try to call selection.stroke() on the second layer. 

 

The same problem occurs iun both Photoshop CC 2020 and PhotoShop CC 2021.

 

Here is my script:

 

#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 gray = new SolidColor;
gray.rgb.hexValue = '505050';
// app.documents.add();
doc = app.activeDocument;

doc.resizeCanvas(UnitValue(this.doc.width + 100,"px"),
UnitValue(this.doc.height + 100,"px"));

var newLayer = doc.artLayers.add();
newLayer.kind = LayerKind.NORMAL;
newLayer.name = "Frame Layer 1";
doc.activeLayer = newLayer;
// doc.selection.select([[10, 10], [494, 10], [494, 350], [10,350]], SelectionType.REPLACE, 0, false);
doc.selection.selectAll();
doc.selection.stroke (gray, 50, StrokeLocation.INSIDE,ColorBlendMode.NORMAL,100);
doc.selection.deselect();

var white = new SolidColor;
white.rgbValue = "ffffff";

alert ("Resizing canvas for layer 2");
doc.resizeCanvas(UnitValue(this.doc.width + 100,"px"),
UnitValue(this.doc.height + 100,"px"));
alert ("Adding layer 2");
var newLayer2 = doc.artLayers.add();
alert ("Setting layer 2 kind to normal");
newLayer2.kind = LayerKind.NORMAL;
alert ("Setting layer 2 name");
newLayer2.name = "Frame Layer 2";
alert ("Selecting newLayer2 as active layer");
doc.activeLayer = newLayer2;
alert ("Selecting all of layer 2");
doc.selection.selectAll();
alert ("Drawing stroke for layer 2");
doc.selection.stroke (white, 50, StrokeLocation.INSIDE,ColorBlendMode.NORMAL,100);
alert ("Deselecting");
doc.selection.deselect();

var newLayer3 = doc.artLayers.add();
newLayer3.kind = LayerKind.NORMAL;
newLayer3.name = "Frame Layer 3";
doc.activeLayer = newLayer3;
// doc.selection.select([[10, 10], [494, 10], [494, 350], [10,350]], SelectionType.REPLACE, 0, false);
doc.selection.selectAll();
doc.selection.stroke (gray, 50, StrokeLocation.INSIDE,ColorBlendMode.NORMAL,100);
doc.selection.deselect();

}
catch(e)
{
alert ("Failed to draw selection: " + e.message);
}
finally
{
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
};
};

 

 

 

TOPICS
Actions and scripting, Bug, Crash or freeze, Problem or error

Views

37

Likes

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

Internal error when drawing a stroke on a selection

Community Beginner ,
Nov 15, 2020

Copy link to clipboard

Copied

I am trying to write a script to add a frame to my photos.  I am running into "internal errors".  I want to expand the canvas size, create a new layer, select all of the new layer, and use selection.stroke to draw a rectangle that fills the added space with a color.  I am getting the internal error when I try to call selection.stroke() on the second layer. 

 

The same problem occurs iun both Photoshop CC 2020 and PhotoShop CC 2021.

 

Here is my script:

 

#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 gray = new SolidColor;
gray.rgb.hexValue = '505050';
// app.documents.add();
doc = app.activeDocument;

doc.resizeCanvas(UnitValue(this.doc.width + 100,"px"),
UnitValue(this.doc.height + 100,"px"));

var newLayer = doc.artLayers.add();
newLayer.kind = LayerKind.NORMAL;
newLayer.name = "Frame Layer 1";
doc.activeLayer = newLayer;
// doc.selection.select([[10, 10], [494, 10], [494, 350], [10,350]], SelectionType.REPLACE, 0, false);
doc.selection.selectAll();
doc.selection.stroke (gray, 50, StrokeLocation.INSIDE,ColorBlendMode.NORMAL,100);
doc.selection.deselect();

var white = new SolidColor;
white.rgbValue = "ffffff";

alert ("Resizing canvas for layer 2");
doc.resizeCanvas(UnitValue(this.doc.width + 100,"px"),
UnitValue(this.doc.height + 100,"px"));
alert ("Adding layer 2");
var newLayer2 = doc.artLayers.add();
alert ("Setting layer 2 kind to normal");
newLayer2.kind = LayerKind.NORMAL;
alert ("Setting layer 2 name");
newLayer2.name = "Frame Layer 2";
alert ("Selecting newLayer2 as active layer");
doc.activeLayer = newLayer2;
alert ("Selecting all of layer 2");
doc.selection.selectAll();
alert ("Drawing stroke for layer 2");
doc.selection.stroke (white, 50, StrokeLocation.INSIDE,ColorBlendMode.NORMAL,100);
alert ("Deselecting");
doc.selection.deselect();

var newLayer3 = doc.artLayers.add();
newLayer3.kind = LayerKind.NORMAL;
newLayer3.name = "Frame Layer 3";
doc.activeLayer = newLayer3;
// doc.selection.select([[10, 10], [494, 10], [494, 350], [10,350]], SelectionType.REPLACE, 0, false);
doc.selection.selectAll();
doc.selection.stroke (gray, 50, StrokeLocation.INSIDE,ColorBlendMode.NORMAL,100);
doc.selection.deselect();

}
catch(e)
{
alert ("Failed to draw selection: " + e.message);
}
finally
{
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
};
};

 

 

 

TOPICS
Actions and scripting, Bug, Crash or freeze, Problem or error

Views

38

Likes

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
Nov 15, 2020 0
Adobe Community Professional ,
Nov 15, 2020

Copy link to clipboard

Copied

wrong

 

white.rgbValue = "ffffff";

 

right

 

white.rgb.hexValue = "ffffff";

 

Likes

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
Reply
Loading...
Nov 15, 2020 0
Community Beginner ,
Nov 15, 2020

Copy link to clipboard

Copied

The PhotoShop CC Javascript Reference document states that the RGBColor class's properties include blue, green, red, typename, and hexValue.  It does not talk about a property named "rgb".

 

 

 

 

Likes

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
Reply
Loading...
Nov 15, 2020 0
Community Beginner ,
Nov 15, 2020

Copy link to clipboard

Copied

But on the other hand, up above, when I define the variable "gray", I am using a property named "rgb".  

Likes

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
Reply
Loading...
Nov 15, 2020 0
Community Beginner ,
Nov 15, 2020

Copy link to clipboard

Copied

Not to mention the fact that I tried to use a property named "rgbValue" instead of "hexValue".  

I wish there was a way to edit comments.

Likes

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
Reply
Loading...
Nov 15, 2020 0
Community Beginner ,
Nov 15, 2020

Copy link to clipboard

Copied

I was using SolidColor objects instead of RGBColor objects, which is what I meant to use.  That's why the properties were wrong.  I started with a bit of cut and paste code, and I didn't notice the difference in color type objects.

Likes

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
Reply
Loading...
Nov 15, 2020 0
Community Beginner ,
Nov 15, 2020

Copy link to clipboard

Copied

Many thanks for pointing out my error.  I was afraid I'd have to give up this approach, and I like using separate layers for each piece of the frame.

Likes

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
Reply
Loading...
Nov 15, 2020 0