Activity › Forums › Adobe After Effects Expressions › Remove all fills in a shape layer?
-
Remove all fills in a shape layer?
Posted by Linus Nystrom on September 2, 2015 at 4:58 pmHi!
Im trying to make a little script where I basically want to select a shape layer, press a button, and that will make it duplicate and delete all the fills from all the shapes inside.
I’ve succeeded with the duplication bit, and I’ve figured out how to ADD properties (like fills or strokes) via the script, but I cant figure out how to access the fill attribute without knowing the exact path (which I dont since I dont know how many shapes the layer contain).
Im thinking there must be a short way of searching through the layer, and if the shape contains a fill, delete it (or make it 0% opacity).
Thanks a lot!
Arun Chaudhary replied 8 years, 10 months ago 5 Members · 7 Replies -
7 Replies
-
Miguel De mendoza
September 2, 2015 at 8:41 pmTry this:
var proj = app.project;
var layer = proj.activeItem.selectedLayers[0];
var contents = layer.property("ADBE Root Vectors Group");function removeFill(){
if(!layer || !(layer instanceof ShapeLayer)){
alert("Select a shape layer");
return;
}
for(i = 1; i <= contents.numProperties ; i++){
var shape = contents.property(i).property("Contents");
if(shape.property("ADBE Vector Graphic - Fill")){
shape.property("ADBE Vector Graphic - Fill").remove();
}
}
}removeFill();
-
Linus Nystrom
September 3, 2015 at 7:47 amOh wow, That works perfectly, and a much fewer lines than mine 😀
Thanks a lot!This works awesome if all shapes are placed directly in the contents level. If If I would like to step this up a notch, to make it search deeper, would the easiest way be to make an if statement for each possible level?
-
Miguel De mendoza
September 3, 2015 at 8:38 amFor acomplish that you need to edit removeFill() function to be recursive, in pseudo pseudo-code something like this:
function removeFill(node):
if node[i].numProperties > 0 do->
for nodes in node do->
if node[i] is shape do-> remove fill
else if do -> removeFill(node[i])removeFill(contents)
For sure you will need to work on it, because accesing properties on shape layer can be tricky. I recomend you to make a “prototype layer” with saveral shapes on diferent levels(as messy as you can to check the “worst case”) and start accesing manualy to each property by index to see the structure .
-
Xavier Gomez
September 3, 2015 at 9:15 amThe following will work in your case.
Choose handler=myHandler1 to remove all fills, and myHandler2 to set opacity to 0.
It’s fairly generic, but you dont need to write it that way (with a separate handler function) if you only have one thing to do with those fills.Xavier.
// handler : g should be a property group that can be added to a shape (empty group / path /stroke / fill / trim path etc)
function myHandler1(g){
if (g.matchName === "ADBE Vector Graphic - Fill") g.remove();
};
function myHandler2(g){
if (g.matchName === "ADBE Vector Graphic - Fill") g.opacity.setValue(0);
};// main function : g is expected to be a shape layer or a shape group (shape "sublayer")
// handler : what to do with the addable content of g
// recursive, and recurses backwards, in case some children are removed...
// doesnt scout the transform group, only addable things
function scoutContent(g, handler){
var n, child;
if (!g.content) return;
g = g.content;
for (n=g.numProperties; n>0; n--){
child = g.property(n);
handler(child);
if (Object.isValid(child) && child.content) scoutContent(child, handler);
};
};scoutContent(app.project.activeItem.selectedLayers[0], myHandler2);
-
Linus Nystrom
September 3, 2015 at 2:21 pmOuff!
I will have try to get this to work with my script, thanks a lot mate!
-
John Colombo
November 8, 2016 at 12:26 amGive this one a try! I was looking for the same feature to quickly remove fills. With that in mind, I took some snippets from Miguel’s code and made it loop through all the selected layers.
This script will toggle the fills without removing them.
Also, holding Alt (or Option) will toggle strokes instead of fills. Watch out for the “<=” in the second for(){} loop, the code box seems to mess it up.
Cheers!
// Define variables
app.beginUndoGroup("Remove Fill on Shape Layer");
var myComp = app.project.activeItem;
var myLayer = myComp.selectedLayers;
var myKeyState = ScriptUI.environment.keyboardState;try {
for (var i=0;i
John Colombo
Lead Creator
1Resonant Creation
http://www.1resonant.com -
Arun Chaudhary
September 11, 2017 at 1:52 pmHi, I need a little help
John Colombo script works fine for active comp. if this script works for selected comp. in a project
and add a stroke in all shape layer stroke width can be set.Thank you
Arun
Reply to this Discussion! Login or Sign Up