FORUMS: list search recent posts

Finding color property of a shape layer.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
joshua faget
Finding color property of a shape layer.
on Sep 22, 2016 at 3:43:33 am

Hello,

Is there an efficient way to find the "Fill" color of a shape layer. As a shape layer can have multiple shapes inside, I want my script to be able to find all fills and replace them. I can do the replacement part, but I can't figure out a way to efficiently find the fills. Also Im running into trouble when there are fills that are grouped a couple of times.

Thank you.


Return to posts index

Xavier Gomez
Re: Finding color property of a shape layer.
on Sep 22, 2016 at 7:41:54 am

To scout a shape layer, you can use a generic recursive function like the one below:

function recurseShape(g, groupHandler){
// g shape layer or group inside a shape ( should have a content property )
// groupHandler : what do do with each group

if (!g.content) return; // doesnt apply

groupHandler(g);

if (!g.content.property("ADBE Vector Group")) return;

for (var n=1; n<=g.content.numProperties; n++){
if (g.content.property(n).matchName==="ADBE Vector Group") recurseShape(g.content.property(n), groupHandler);
};
};


The argument 'groupHandler' is itself a function and tells what to do with the immediate content of the shape layer or group inside it.
In case the 'thing to do' is remove or reorganize children, it should be written in a way no error is thrown (!)
For instance, to change fills to gradient fills, it could be:

function myGroupHandler_changeFillToGFill(g){
// g shape layer or group inside a shape ( should have a content property )

if (!g.content || !g.content.property("ADBE Vector Graphic - Fill")) return;

for (var n=1; n<=g.content.numProperties; n++){
if (g.content.property(n).matchName==="ADBE Vector Graphic - Fill"){
g.content.property(n).remove();
g.content.addProperty("ADBE Vector Graphic - G-Fill").moveTo(n);
};
};
};


And apply this way:

var comp = app.project.activeItem;
app.beginUndoGroup("Change Fills to G-Fills");
recurseShape(comp.layer(1), myGroupHandler_changeFillToGFill);
app.endUndoGroup();


That's one way to do, you can rewrite your own, but hopefully you get the spirit.

Xavier


Return to posts index

joshua faget
Re: Finding color property of a shape layer.
on Sep 22, 2016 at 9:06:17 pm

Wow, thank you very much, this is really useful.

But unfortunately I am running into an issue. I got it to change the fill with a value in a predefined variable, BUT it seems to be breaking the recursion when I try to slip some more information in the functions.

var rgb = [0.5, 1, 1];


ChangeColorButton.onClick = function() {
var Color = rgb;

//TheSelectedLayer
var Selection = app.project.activeItem.selectedLayers[0];


//RECURSION FUNCTION
function recurseShape(g, groupHandler, rgb) {
// g shape layer or group inside a shape ( should have a content property )
// groupHandler : what do do with each group

if (!g.content) return; // doesnt apply

groupHandler(g, rgb);
if (!g.content.property("ADBE Vector Group")) return;

for (var n = 1; n &lt;= g.content.numProperties; n++) {
if (g.content.property(n).matchName === "ADBE Vector Group") recurseShape(g.content.property(n), groupHandler);
};
};

//WHAT TO DO
function myGroupHandler_changeFillToGFill(g, rgb) {
// g shape layer or group inside a shape ( should have a content property )
if (!g.content || !g.content.property("ADBE Vector Graphic - Fill")) return;

for (var n = 1; n &lt;= g.content.numProperties; n++) {
if (g.content.property(n).matchName === "ADBE Vector Graphic - Fill") {
g.content.property(n).property(4).setValue(rgb);
};
};
};


//EXECUTION
app.beginUndoGroup("Change Fills to G-Fills");
recurseShape(Selection, myGroupHandler_changeFillToGFill, Color);
app.endUndoGroup();

}


Return to posts index


joshua faget
Re: Finding color property of a shape layer.
on Sep 22, 2016 at 9:12:32 pm

Disregard my previous comment... I overly complicated it for no reason.

alert('Thanks Xavier') // :D


Return to posts index

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