Hi All,
I'm trying to perform what appeared initially to be a trivial task. I want to use C# (couldn't get that working on the saveAs keeps failing with such a generic error it's not worth repeating here) to create a script / tool to open a photoshop file(s), change text on a given layer (working, but wasn't easy due to, I think, a corrupt layer), change the color of a layer which I believe has an adjustment layer attached. (see Figure A below) The problem is I can't form a coherent question because this software and / or tool is complicated to me.
I'm a pretty technical person, but feel this software was written to make the lives of it' s authors easier and not that of the developers. Forcing developers to look up stupid id only to passthem back to the api is harsh and poor design (i.e. IdToTypeId, getByName() -> throws an error if not found awful).
Below is a image of the layer I'm having issue changing the color for. The specific error I get is rather vague, but in true Adobe software practice and form. The tool complains, "The command "Fill" is not currently available. (see Figure B below) The following is the pertinent part of the javascript code (.jsx) used to produced the desired effect:
const parent = firstOrDefault("T-Shirt", doc.layerSets);
const shirtColorLayer = parent ? parent.artLayers.getByName("T-shirt Color"):
doc.artLayers.getByName("T-shirt Color");
if(!shirtColorLayer && shirtColorLayer.name === "T-shirt Color"){
return;
}
shirtColor = new SolidColor).rgb.hexValue = "F0EC74"; //Cornsilk
shirtColorLayer.visible = true;
doc.activeLayer = shirtColorLayer;
doc.selection.fill(shirtColor, ColorBlendMode.NORMAL,100, false);
The error message and hopes of work arounds are all deadends right now. I don't know the software well enough to form the right questions or describe the exact layer type I'm dealing with. Others have used similar code to perform the same trivial task, but I beleive this layer is somehow different. But not in a way that could not have been abstracted from the developers using this awfule API. I had no idea Adobe was this horrific. It certainly present as a proper technology company, but man is "presents" the operative (key) word. Any help on terms, understand and code assistance with this API would be greatly appreciated. Please explain like I'm 3 years old and don't know anything about Adobe. That said there is no need to explain proper API's like javascript, C#, or other programming topics.
Figure A
Figure B
Thank you @Dariusz1989 . I appreciate the prompt and swift reply. This task is important to my client so I kept searching and found a piece of code that seems to be, just the right does. I won't pretend I understand what it does or how it is doing it and not sure I really want to. The solutions I found is as follow:
function setFillColor(c) {
try {
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID('contentLayer'),
...
Copy link to clipboard
Copied
If my memory serves me right this is a shape layer... you need to "Rasterize Layer" it if you want to fill it with color OR create layer mask over it (if that's its name) and then use it to colorize it.
And welcome to the club ! I'm using c++/javascript and soon I can go to the opera & perform thanks to all the shouts/screams I did over last few years... with adobe api...
Copy link to clipboard
Copied
Thank you @Dariusz1989 . I appreciate the prompt and swift reply. This task is important to my client so I kept searching and found a piece of code that seems to be, just the right does. I won't pretend I understand what it does or how it is doing it and not sure I really want to. The solutions I found is as follow:
function setFillColor(c) {
try {
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID('contentLayer'), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum'));
d.putReference(stringIDToTypeID('null'), r);
var d1 = new ActionDescriptor();
var d2 = new ActionDescriptor();
var d3 = new ActionDescriptor();
d3.putDouble(stringIDToTypeID('red'), c.rgb.red);
d3.putDouble(stringIDToTypeID('green'), c.rgb.green);
d3.putDouble(stringIDToTypeID('blue'), c.rgb.blue);
d2.putObject(stringIDToTypeID('color'), stringIDToTypeID('RGBColor'), d3);
d1.putObject(stringIDToTypeID('fillContents'), stringIDToTypeID('solidColorLayer'), d2);
var d4 = new ActionDescriptor();
d4.putBoolean(stringIDToTypeID('fillEnabled'), true);
d1.putObject(stringIDToTypeID('strokeStyle'), stringIDToTypeID('strokeStyle'), d4);
d.putObject(stringIDToTypeID('to'), stringIDToTypeID('shapeStyle'), d1);
executeAction(stringIDToTypeID('set'), d, DialogModes.NO);
}
catch (e) { throw(e); }
}
Adobe is a shameful excuse for a technology company. They should consult me. I'd get their API in proper form and fashion. It would be self-explainatory, make the developer a rock-star and be as popular as C# & .NET itself. Tall claims? I've done it before. Adobe tools, API, apps, etc. need a thourough refactoring. It's long overdue, imho.