ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Group shapes

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mahdi Mor
Group shapes
on Jun 16, 2017 at 5:19:25 pm

how to group shapes with script??
i want to group highlighted shapes with script.
thanks



Return to posts index

Dan Ebberts
Re: Group shapes
on Jun 16, 2017 at 5:50:38 pm

The only way I know of is to select the shapes and then have the script execute the "Group Shapes" menu command.

Dan



Return to posts index

Mahdi Mor
Re: Group shapes
on Jun 16, 2017 at 6:46:55 pm

thanks , 1 more Q .
how can i select them (by script ).??


Return to posts index


Dan Ebberts
Re: Group shapes
on Jun 16, 2017 at 7:12:05 pm

Something like this, probably:


var myContents = myLayer.property("ADBE Root Vectors Group");
myLayer.selected = false;
for (var i = 1; i <= myContents.numProperties; i++){
myContents.property(i).selected = true;
}


It might depend on how your shape layer is structured.

Dan



Return to posts index

Mahdi Mor
Re: Group shapes
on Jun 16, 2017 at 7:22:42 pm

yay ,thank you very much.


Return to posts index

JuanLuis Vich
Re: Group shapes
on Mar 9, 2019 at 1:40:41 am

hi!
I was trying to group some shape props along a bunch of selected layers, but it seems I cannot make it work on all the selected layers, but only on the first one.
Is there a chance to make it work so I can select some layers, and then apply the script so all the contents they have inside get grouped without stoping once the first layer is done? Maybe that's not possible and it should work on every layer individually?
this is the code I was trying to make work:

var myLayers = app.project.activeItem.selectedLayers;
var myLayer;
for (var i = 0; i < myLayers.length; i++){

myLayer = myLayers[i];
var myContents = myLayer.property("ADBE Root Vectors Group");
myLayer.selected = false;
for (var i = 1; i <= myContents.numProperties; i++){
myContents.property(i).selected = true;
app.executeCommand(3741);//group shapes
}

}



Thanks!


Return to posts index


Dan Ebberts
Re: Group shapes
on Mar 9, 2019 at 3:11:12 am

You have a nested loop where you're using the same loop variable name (i) for both loops. You need to change one of them. I usually use j for the inner loop.


Dan



Return to posts index

JuanLuis Vich
Re: Group shapes
on Mar 9, 2019 at 4:11:40 am

oh! thanks! I missed that!

I changed the inner loop to be j, but it seems the execute command is not working at all. Its weird, when I select the layers individually, it works great, but if more than 1 layer is selected, it just loops and selects all the properties at the same but no grouping at all...


Return to posts index

Dan Ebberts
Re: Group shapes
on Mar 9, 2019 at 4:35:06 am

I don't know for sure, but maybe the menu command doesn't work if more than one layer is selected. If that's the case, you'll probably have to make sure the layers are selected one at a time before you start the inner loop.


Dan



Return to posts index


JuanLuis Vich
Re: Group shapes
on Mar 9, 2019 at 6:21:32 am

mm yes, it seems it will have to work that way... thanks for the ideas!


Return to posts index

JuanLuis Vich
Re: Group shapes
on Mar 23, 2019 at 9:25:19 pm

hi!
I've been trying to figure out how to make sure the layers are selected one at a time before starting the inner loop with no luck... do you have any hint or ref to get the right direction?
Thanks!


Return to posts index

Dan Ebberts
Re: Group shapes
on Mar 23, 2019 at 10:02:35 pm

First you would loop through all currently selected layers and deselect each one. Then you would select the layer you want to apply the preset to.

Dan



Return to posts index


JuanLuis Vich
Re: Group shapes
on Mar 23, 2019 at 10:44:43 pm

of course!
thanks!


I made it work with this
Do you think the code is ok, or too messy? it's working, btw ☺




var myComp = app.project.activeItem;
var mySelectedLayers = myComp.selectedLayers;
///
for (var i = 1; i <= myComp.numLayers; i++){
myComp.layer(i).selected = false;

}

///
for (var i = 1; i <= myComp.numLayers; i++){
var myContents = myComp.layer(i).property("ADBE Root Vectors Group");

for (var j = 1; j <= myContents.numProperties; j++){
myContents.property(j).selected = true;
app.executeCommand(3741);//group shapes

}
myComp.layer(i).selected = false;
}



Return to posts index

Dan Ebberts
Re: Group shapes
on Mar 23, 2019 at 11:44:00 pm

I think I might change that first loop to something like this:


for (var i = 0; i < mySelectedLayers.length; i++){
mySelectedLayers[i].selected = false;
}


but it looks pretty good.


Dan



Return to posts index

JuanLuis Vich
Re: Group shapes
on Mar 24, 2019 at 1:29:08 am

thanks a lot for the help!!


Return to posts index


Santi Agustí
Re: Group shapes
on Mar 25, 2019 at 3:17:33 am

Hi! sorry to bother with the group thing! I was giving a try to the script you posted here with different kind of grouping ( shape layer with 4 pre- groups to group, another shape layer with 3 and 2).
Then I found a really odd behaviour when applying the script, it generates a group with several unexpected subgroups, it always creates the same pattern, groups inside groups,( and letting one element outside the group and when selecting more than 2 groups to group).

I added an image to try to make it a bit more clear.

On the image, I was trying to group the groups (001,002,003,004) into a single group, but everything seemed to work with that strange behaviour

I also added the same file I was applying the script into, just in case
13221_groupsmadness.aep.zip



I don't know if there is some line to tweak the script to avoif that infinite looping of creating subgroups when calling the command (3741) or maybe its some kind of bug or limitation when grouping via calling the command with the script?


Return to posts index

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