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