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

Changing the color of a solid

New Here ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

I have a script that allows me to find a solid and change its color. Right now I am able to create a blue solid and change it to any color I need but if I try to create a solid of a different color and change that one the script is unable to find the solid and change it.

This is the particular part of the script that is used to change it

            if(curLayerSource instanceof SolidSource && curLayerSource.color == "0,0,1"){

                curLayerSource.color = [1,0,0];

                }

The first "0,0,1" is what color the solid is and in the second line, [1,0,0] is what color the solid needs to change to. I can change the color in the second line to anything I want and it will work but if I try to create a solid that is for example, grey and replace the "0,0,1" with "0.800,0.800,0.800" it won't find the grey solid and change it. Any idea what I'm doing wrong? Here is the full script below as well.

try{

    //----------------------------------Variables----------------------------------

    var proj = app.project;

    var itemTotal = proj.numItems;

    var solidColor = [1, 0, 0];

    var curItem, curComp, totalComps, totalLayers, curLayer, curLayerIndex, curLayerSource;

    var itemAry = new Array();

    //----------------------------------Loop through project items----------------------------------

    app.beginUndoGroup("Blue to Red");

    for(var i = 1; i <= itemTotal; i++){

        //item assignment

        curItem = proj.item(i);

        //Check if item is comp

        if(curItem instanceof CompItem){

            itemAry[itemAry.length] = curItem;

            }

        }

   

        totalComps = itemAry.length;

  

    for(var c = 0; c < totalComps; c++){

//--------------------------------------------------------------

            //----------------------------------Variable assignment----------------------------------

            curComp = itemAry;

            totalLayers = curComp.numLayers;

           

            //Loop through layers

            for(var l=1; l<=totalLayers; l++){

                curLayer = curComp.layer(l);

                if (curLayer.source == null) continue;

                curLayerIndex = curLayer.index;

                curLayerSource = curLayer.source.mainSource;

               

              

            //------Check layer, if it is a solid and it's blue, change it to red (Change this to set new color)———

            if(curLayerSource instanceof SolidSource && curLayerSource.color == "0,0,1"){

                curLayerSource.color = [1,0,0];

                }

           

                //Update info panel with progress

                writeLn("Layer " + curLayerIndex.toString() + " updated");

                }

//------------------------------------------------------------------          

        }

    app.endUndoGroup();

    alert("All Done.");

   

//If an error occurs, catch it and show me

}catch(err){

    alert("Error at line # " + err.line.toString() + "\r" + err.toString());

   

}

TOPICS
Scripting

Views

1.8K

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
Enthusiast ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

LATEST

After Effects likes to mess with numbers.

So in your case, if you will alert the Solid's color, you might get something like this:

Screen Shot 2018-08-17 at 10.04.48.png

I recommend you to use Math.round or .toFixed ​to check those values.

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