Adobe After Effects Expressions Forum
Remove all fills in a shape layer?
Remove all fills in a shape layer?
by linus nystrom on Sep 2, 2015 at 4:58:47 pm


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!

Re: Remove all fills in a shape layer?
by Miguel de Mendoza on Sep 2, 2015 at 8:41:22 pm

Try this:

var proj = app.project;
var layer = proj.activeItem.selectedLayers[0];
var contents ="ADBE Root Vectors Group");

function removeFill(){
if(!layer || !(layer instanceof ShapeLayer)){
alert("Select a shape layer");
for(i = 1; i <= contents.numProperties ; i++){
var shape ="Contents");
if("ADBE Vector Graphic - Fill")){"ADBE Vector Graphic - Fill").remove();


Re: Remove all fills in a shape layer?
by linus nystrom on Sep 3, 2015 at 7:47:25 am

Oh wow, That works perfectly, and a much fewer lines than mine :D
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?

Re: Remove all fills in a shape layer?
by Miguel de Mendoza on Sep 3, 2015 at 8:38:43 am

For 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])


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 .

Re: Remove all fills in a shape layer?
by Xavier Gomez on Sep 3, 2015 at 9:15:20 am

The 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.


// 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 =;
if (Object.isValid(child) && child.content) scoutContent(child, handler);

scoutContent(app.project.activeItem.selectedLayers[0], myHandler2);

Re: Remove all fills in a shape layer?
by linus nystrom on Sep 3, 2015 at 2:21:46 pm


I will have try to get this to work with my script, thanks a lot mate!

Re: Remove all fills in a shape layer?
by John Colombo on Nov 8, 2016 at 12:26:14 am

Give 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.


// 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
if (myLayer[i] instanceof ShapeLayer){

//alert("This is a shape");
var contents = myLayer[i].property("ADBE Root Vectors Group");

for(s = 1; s <= contents.numProperties ; s++){
var shape ="Contents");
if (myKeyState.altKey == true){
if("ADBE Vector Graphic - Stroke").active == false){"ADBE Vector Graphic - Stroke").enabled = true;
}else{"ADBE Vector Graphic - Stroke").enabled = false}
if("ADBE Vector Graphic - Fill").active == false){"ADBE Vector Graphic - Fill").enabled = true;
}else{"ADBE Vector Graphic - Fill").enabled = false;}

continue //skip non-shape layers
alert(err.line + "n" + err.toString());

John Colombo
Lead Creator
1Resonant Creation

Re: Remove all fills in a shape layer?
by Arun Chaudhary on Sep 11, 2017 at 1:52:09 pm

Hi, 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