• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

.fill is not a function, Error 24

Community Beginner ,
May 18, 2017 May 18, 2017

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...

photoshop.png
    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?

TOPICS
Actions and scripting

Views

2.0K

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
community guidelines
Adobe
Community Expert ,
May 18, 2017 May 18, 2017

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.

Votes

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
community guidelines
Contributor ,
May 19, 2017 May 19, 2017

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 );

}

Votes

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
community guidelines
Community Beginner ,
May 19, 2017 May 19, 2017

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 ?

Votes

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
community guidelines
Contributor ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

It's inadvertently ............

Votes

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
community guidelines
Community Beginner ,
May 19, 2017 May 19, 2017

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

Votes

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
community guidelines
Community Expert ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

Hi andreyo28152172,

Possible are

"None", "Rd  ", "Orng", "Ylw ", "Grn ", "Bl  ", "Vlt ", "Gry "

but yes, thats all.

Votes

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
community guidelines
Contributor ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

Yes !

Votes

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
community guidelines
Community Beginner ,
May 19, 2017 May 19, 2017

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

Votes

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
community guidelines
Contributor ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

???

Votes

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
community guidelines
Community Beginner ,
May 19, 2017 May 19, 2017

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 ?

Votes

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
community guidelines
Community Expert ,
May 20, 2017 May 20, 2017

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:

  • colorize the "layer label color" of kind.solidfilled and kind.patternfilled and "pixelbasedfilled" layers = kind.normal ???

(in this case ONLY 7 + 1 colors are possible ["Rd  ", "Orng", "Ylw ", "Grn ", "Bl  ", "Vlt ", "Gry "] + [None] )

or

  • fill a pixel layer with your wished color and/or
  • change the color of a shape layer and/or
  • change the color of the pattern inside a pattern layer ???

Votes

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
community guidelines
Community Beginner ,
May 22, 2017 May 22, 2017

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!

Votes

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
community guidelines
Community Expert ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

andreyo28152172

OK.

You never want to colorize the color label of a layer. Is this right?

  • Change the color of a shape layer can be recorded with script listener (is possible)
  • But how do you change the color inside a pattern layer. IMHO you should change the pattern itself. Or you use a layer effect( eg color overlay) instead.

Or can you describe exactly how you can do this "by hand"? The most things that you can "do by hand" are also scriptable.

Votes

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
community guidelines
Community Beginner ,
May 23, 2017 May 23, 2017

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!

Votes

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
community guidelines
Community Expert ,
May 23, 2017 May 23, 2017

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 …

Votes

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
community guidelines
Community Beginner ,
May 23, 2017 May 23, 2017

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();
}

Votes

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
community guidelines
Community Expert ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines