FORUMS: list search recent posts

Find and Replace colours in whole project

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Harry Hoag
Find and Replace colours in whole project
on Jan 31, 2019 at 2:39:22 pm

Hi

Anyone know of a script that will let me find and replace all the colour fields in shape layers throughout a massive project?

Classic client error, been given the wrong colour pallet at the start of the job, now at the end of the job I need to swap around 6 or so stroke and fill colours on a gazillion shape layers through a gazillion precomps. A script would be mighty hand right now.

And ideas would be much appreciated ☺

thanks
H


Return to posts index

Oleg Pirogov
Re: Find and Replace colours in whole project
on Feb 2, 2019 at 9:28:13 am

This script substitutes one color for another in all feasible properties (like effects, shapes' fill colors etc) in all comps and layers:



//converts a color channel from [0,1] range to hex string
function channelToHex(channel){
if (channel<0) return "00";
if (channel>1) return "FF";

var channelInt = Math.round(channel*255);
var hex = channelInt.toString(16);
if (hex.length == 1) hex = "0" + hex;
return hex.toUpperCase();
}

//recursive function to look for color properties; "path" variable is rudimental
function colorSearch(thePropertyGroup, path, targetColor, substituteColor){
for (var i=1; i<=thePropertyGroup.numProperties; i++){
currentProperty = thePropertyGroup.property(i);

//checking, if it's a property and not a property group
if (currentProperty.propertyType == PropertyType.PROPERTY){
//checking, if it's a color property
if (currentProperty.propertyValueType == PropertyValueType.COLOR){
//checking, if color value equals the targetColor (8 bpc) or is its 8 bpc equivalent (16, 32 bpc)
if ([channelToHex(currentProperty.value[0]), channelToHex(currentProperty.value[1]), channelToHex(currentProperty.value[2])].join("") == targetColor){
try{
currentProperty.setValue(substituteColor);
}
//mostly for handling hidden color layers
catch(err){
}
}
}
}
else{
colorSearch(currentProperty, path+" -> "+currentProperty.name, targetColor, substituteColor);
}
}
}

function main(){
//dialog window
var dialogWindow = new Window ("dialog", "Color Substitution");

var targetColorGroup = dialogWindow.add("group");
targetColorGroup.alignment = "right";
targetColorGroup.add("statictext", undefined, "Target color:");

var targetColorBoxGroup = targetColorGroup.add("group");
targetColorBoxGroup.spacing = 0;
targetColorBoxGroup.add("statictext", undefined, "#");
var targetColorHex = targetColorBoxGroup.add("edittext", undefined, "FFFFFF");


var substitutionColorGroup = dialogWindow.add("group");
substitutionColorGroup.alignment = "right";
substitutionColorGroup.add("statictext", undefined, "Substitute with:");

var substitutionColorBoxGroup = substitutionColorGroup.add("group");
substitutionColorBoxGroup.spacing = 0;
substitutionColorBoxGroup.add("statictext", undefined, "#");
var substitutionColorHex = substitutionColorBoxGroup.add("edittext", undefined, "0000FF");

var buttonsGroup = dialogWindow.add("group");
buttonsGroup.add("button", undefined, "Ok");
buttonsGroup.add("button", undefined, "Cancel");

var resp = dialogWindow.show();

if (resp == 2){
return;
}



var prj = app.project;

//converts hex string to [r, g, b, a] color; a = 1
var hexToRGBa = function(hexColorText){
hex = parseInt(hexColorText, 16);
return [hex >> 16, hex >> 8 & 0xFF, hex & 0xFF, 255]/255;
}

var targetColor = targetColorHex.text;
var substituteColor = hexToRGBa(substitutionColorHex.text);

//searching in every comp...
for (i=1; i<=prj.numItems; i++){
if (prj.item(i).typeName == "Composition"){
currentComp = prj.item(i);

//...and in every layer
for (j=1; j<=currentComp.layers.length; j++){
colorSearch(currentComp.layer(j), currentComp.layer(j).name, targetColor, substituteColor);
}
}
}

}

main();


Works fine as far as I've tested it.


Return to posts index

Harry Hoag
Re: Find and Replace colours in whole project
on Feb 3, 2019 at 9:24:07 pm

wow thanks man, I'll give it a go!


Return to posts index


Michael Szalapski
Re: Find and Replace colours in whole project
on Feb 7, 2019 at 10:25:25 pm

In the future, you might check out Ray Dynamic Color. It's a very handy tool that does this and a lot more.

- The Great Szalam
(The 'Great' stands for 'Not So Great, in fact, Extremely Humble')

No trees were harmed in the creation of this message, but several thousand electrons were mildly inconvenienced.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]