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

Having Error 25 Expected When using index.Of in function

Explorer ,
May 23, 2019 May 23, 2019

Hi i manage all my day trying to get thing out but i don't understand this error.

Here is my code:

error25.PNG

f= File.openDialog("select file");

var theLayers = app.activeDocument.layers; 

fillWhichColor(f.name , theLayers[1]);

function fillWhichColor(theNameString,theLayerFill)

{

   

    if (theNameString.indexOf('color1')) changeSolidColor(theLayerFill, 255 254, 255);

    if (theNameString.indexOf('color2')) changeSolidColor(theLayerFill, 210, 135, 94);

    if (theNameString.indexOf('color3')) changeSolidColor(theLayerFill, 130, 140, 87);

    if (theNameString.indexOf('color4')) changeSolidColor(theLayerFill, 247, 211, 192);

    if (theNameString.indexOf('color5')) changeSolidColor(theLayerFill, 237, 216, 63);

    if (theNameString.indexOf('color6')) changeSolidColor(theLayerFill, 237, 48, 48);

    if (theNameString.indexOf('color7')) changeSolidColor(theLayerFill, 208, 212, 233);

    if (theNameString.indexOf('color8')) changeSolidColor(theLayerFill, 109, 179, 220);

}

////// change color of solid color layer //////

function changeSolidColor (theIdentifier, theR, theG, theB) {

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc4 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        ref1.putIdentifier ( stringIDToTypeID( "contentLayer" ), theIdentifier );

    desc4.putReference( idnull, ref1 );

    var idT = charIDToTypeID( "T   " );

        var desc5 = new ActionDescriptor();

        var idClr = charIDToTypeID( "Clr " );

            var desc6 = new ActionDescriptor();

            var idRd = charIDToTypeID( "Rd  " );

            desc6.putDouble( idRd, theR );

            var idGrn = charIDToTypeID( "Grn " );

            desc6.putDouble( idGrn, theG );

            var idBl = charIDToTypeID( "Bl  " );

            desc6.putDouble( idBl, theB );

        var idRGBC = charIDToTypeID( "RGBC" );

        desc5.putObject( idClr, idRGBC, desc6 );

    var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

    desc4.putObject( idT, idsolidColorLayer, desc5 );

  executeAction( idsetd, desc4, DialogModes.NO );

};

TOPICS
Actions and scripting
3.3K
Translate
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

correct answers 1 Correct answer

People's Champ , May 23, 2019 May 23, 2019

for сс2018+

change

fillWhichColor(f.name , theLayers[1]);

to

fillWhichColor(f.name , theLayers[1].id);

Translate
Adobe
Community Expert ,
May 23, 2019 May 23, 2019

looks like you are missing a comer ",".

JJMack
Translate
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
Explorer ,
May 23, 2019 May 23, 2019

Thank you @JJMack, i fixed it, but another error:

Capture.PNG

Translate
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
Explorer ,
May 23, 2019 May 23, 2019

My app document is in CMYK mode, do you think that's the reason ? i am searching but there are no topic in this forum how to change color shape using script in CMYK mode. JJMack

Translate
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, 2019 May 23, 2019

The message state that one of your argument  2 is not a numeric. That the function requires a number.  theIdentifier seems to be a variable argument the second argument which most likely has a none numeric value. In the code you show I do not see where the variavle is set,

JJMack
Translate
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
Explorer ,
May 23, 2019 May 23, 2019

The code i used is from this topic:

change colors in vector shapes - photoshop script

Actually theIdentifier is the layer that contain shape vector need to be filled color.

I don't know how to fix it.

Translate
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, 2019 May 23, 2019

Did you modify that script code? That code seems to set the variable with a get integer of the layer id from the layer descriptor.

var theIdentifier = layerDesc.getInteger(stringIDToTypeID ("layerID"));

The variable should be a whole number in that case.  The error you get  seem to state otherwise.

Post the actual code you are using.

JJMack
Translate
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
People's Champ ,
May 23, 2019 May 23, 2019

for сс2018+

change

fillWhichColor(f.name , theLayers[1]);

to

fillWhichColor(f.name , theLayers[1].id);

Translate
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
Explorer ,
May 23, 2019 May 23, 2019

Thanks All,

you are all right, JJMack is right, i miss undertood about theIdentifier, it must be an LayerID (it mean an Number Interger). I also find that "Layer ID" and "Layer indice" are totally different. When you move an layer X, that indice i  Layer will change,  but the ID of that Layer will not change Layer.id

So i fixed it with r-bin instruction:

fillWhichColor(f.name , theLayers[1].id);

I use CC2017 but it work anyway, that's pretty cool.

Translate
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, 2019 May 23, 2019

I'm not 100% sure, but I think the javascript command indexOf doesn't work with extendscript.

Translate
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
Explorer ,
May 23, 2019 May 23, 2019
LATEST

Chuck Uebele

I am using CC2017 , indexOf is working.

theNameString = "color1-1123335";

alert(theNameString.indexOf('color1'));  give me 0

alert(theNameString.indexOf('color2'));  give me -1

Translate
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