Participant
May 13, 2023
Question
How to change via script a SolidFill layer color on a masked layer
- May 13, 2023
- 3 replies
- 2942 views
- I have a simple file where I cuse the Elliptical Marquee tool to mark a Circle.
- I then add a New Fill Layer - Solid Color (purple).
- I save this file as a project.
- I would then want to change this mask color via a script (JDX, PY, whatever) to a different one (example red).
I tried via JSX with the following code:
// Get the active document
var doc = app.activeDocument;
// Get the "Circle" layer
var circleLayer = doc.layers.getByName("Circle");
// Get the Circle mask
var circleMask = circleLayer.mask;
// Create a new solid color fill layer
var colorLayer = doc.artLayers.add();
colorLayer.kind = LayerKind.SOLIDFILL;
colorLayer.name = "Color Fill";
colorLayer.fillOpacity = 100;
colorLayer.blendMode = BlendMode.NORMAL;
colorLayer.solidColor.rgb.red = 255;
colorLayer.solidColor.rgb.green = 0;
colorLayer.solidColor.rgb.blue = 0;
// Apply the color fill layer as a clipping mask to the Circle mask
circleMask.applyAdd();
colorLayer.move(circleLayer, ElementPlacement.PLACEAFTER);
colorLayer.clipped = true;
However that throws a message:
"Error 8193: You can only change the layer's kind to text or normal" line 12: color
colorLayer.kind = LayerKind.SOLIDFILL;
I've tried modifying the code countless times to no effect. Any help to achieve this would be appreciated or a different approach to take.
