Copy link to clipboard
Copied
Hello, I have a question for the community. I am attempting to write a script(in JavaSCript) that selects the underlined layers(see the image bellow) and applies a color fill to them...
I am not sure why but I get the following error: "Error 24: class2.fill is not a function.
Here is my code, written in JavaScript:
function setColor1(){
var Color = new SolidColor;
Color.rgb.hexValue = '7f7f7f';
var doc = app.activeDocument;
var colorGroup = doc.layerSets.getByName('COLORGROUP');
var class2 = colorGroup.layers.getByName('CLASS2");
alert(class2.kind) // patternfill
class2.fill(Color , undefined, undefined, true):
}
What am I doing wrong?
Copy link to clipboard
Copied
To start with, you're trying to fill a patternfill with a solidfill. You need the right type of layer to fill. To filling with the DOM, AFAIK only works with a pixel based layer, not an layer like patternfill or solidfill. For that, you would want to record changing the color or pattern of one of those layers using scriptlistener, then modify the code to add the color you want.
Copy link to clipboard
Copied
Bonjour
As Chuck Uebele says I have a script with Scriptlistner ....
If you can use it:
//CoulCalc.jsx
var docRef = app.activeDocument;
var Coul = "Vlt ";
// "Gry " "Rd " "Ylw " "Grn " "Bl " "Vlt " "Orng"- gris rouge jaune vert bleu violet orange
var Calque = docRef.activeLayer;
var CalcNom = Calque.name;
CalcCoul(Coul)
function CalcCoul()
{
var idslct = charIDToTypeID( "slct" );
var desc27 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref19 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref19.putName( idLyr, CalcNom );
desc27.putReference( idnull, ref19 );
var idMkVs = charIDToTypeID( "MkVs" );
desc27.putBoolean( idMkVs, false );
executeAction( idslct, desc27, DialogModes.NO );
var idsetd = charIDToTypeID( "setd" );
var desc28 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref20 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref20.putEnumerated( idLyr, idOrdn, idTrgt );
desc28.putReference( idnull, ref20 );
var idT = charIDToTypeID( "T " );
var desc29 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var idClr = charIDToTypeID( "Clr " );
var idOrng = charIDToTypeID( "Vlt " );
desc29.putEnumerated( idClr, idClr, idOrng );
var idLyr = charIDToTypeID( "Lyr " );
desc28.putObject( idT, idLyr, desc29 );
executeAction( idsetd, desc28, DialogModes.NO );
}
Copy link to clipboard
Copied
@dominique filiol thank you! This is very helpful. I have a question regarding your code, You are calling the function CalcCoul(Coul) with the Coul parameter passed in, in the CalCoul function itself there is no reference to that variable... why is that ?
Copy link to clipboard
Copied
It's inadvertently ............
Copy link to clipboard
Copied
@dominique filiol so my understanding is that with this code the colors that i am limited to are "Gry " "Rd " "Ylw " "Grn " "Bl " "Vlt " & "Orng" ? How would you adjust the code so that it applies a color that you pass in as a variable
Copy link to clipboard
Copied
Hi andreyo28152172,
Possible are
"None", "Rd ", "Orng", "Ylw ", "Grn ", "Bl ", "Vlt ", "Gry "
but yes, thats all.
Copy link to clipboard
Copied
Yes !
Copy link to clipboard
Copied
so if i would like to fill a pattern with a rgb color that i am passing into the function what should i do? surely there has to be a way to add color to pattern fill layers via script
Copy link to clipboard
Copied
???
Copy link to clipboard
Copied
I would like to pass in a variable that represents a color into that function ... so for example i have '#7f7f7f' and I want to fill the layer with that color, how would i accomplish that via script ?
Copy link to clipboard
Copied
I'm not sure if I understand you right. And please: set a link to your crossposting on ps-scripts.com
What do you really want:
(in this case ONLY 7 + 1 colors are possible ["Rd ", "Orng", "Ylw ", "Grn ", "Bl ", "Vlt ", "Gry "] + [None] )
or
Copy link to clipboard
Copied
@pixxel schubser I need to accomplish the last 2 actions on the list, change color of shape layer and change color inside pattern layer... I was a bit confused because according to the scripting guide I can change the color of that layer with the .fill command, but apparently not. Thank you for taking your time to respond!
Copy link to clipboard
Copied
OK.
You never want to colorize the color label of a layer. Is this right?
Or can you describe exactly how you can do this "by hand"? The most things that you can "do by hand" are also scriptable.
Copy link to clipboard
Copied
@pixxxel schubser I figured out how to programmatically do the task. i have to select each layer by name, then run the selectAll() command and then run the fill() command on the selection That's it!
Copy link to clipboard
Copied
Hmmh???
Are you sure?
This is what you described in your last posting (but only for the active layer). Please try it by yourself.
This will only works on artLayers with layer.kind.NORMAL …
var Color = new SolidColor;
Color.rgb.hexValue = '7f7f7f';
var aDoc = activeDocument;
alert(aDoc.activeLayer.kind);
aDoc.selection.selectAll();
aDoc.selection.fill(Color);
and not with shape layers and not with patternfill layers and not …
Copy link to clipboard
Copied
This code works ...
function setColor1(c){ | |
var Color = new SolidColor; | |
var x = c.replace('#',''); | |
Color.rgb.hexValue = x; | |
app.activeDocument.activeLayer = app.activeDocument.layers.getByName('CLASS2HEX'); | |
app.activeDocument.selection.selectAll(); | |
app.activeDocument.selection.fill(Color); | |
app.activeDocument.selection.deselect(); | |
} |
Copy link to clipboard
Copied
Again and again and again:
This will only works on artLayers with layer.kind.NORMAL …
and not with shape layers and not with patternfill layers and not …