Quantcast
Channel: Adobe Community : Discussion List - After Effects Scripting
Viewing all articles
Browse latest Browse all 2143

Changing the color of a solid

$
0
0

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[c];

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

   

}


Viewing all articles
Browse latest Browse all 2143

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>