Copy link to clipboard
Copied
Hello After Effects community! I'm looking for some insight from the scripting experts here that I couldn't find with my usual searching.
I'm currently working on a script that at its core will create several shape layers arranged in a specific way to generate templates, though the exact details don't matter for this question.
One part of my script is currently adding two different shape groups to a single shape layer. When a script generates new shape groups it'll place them BELOW the previously generated shape group. I want to know if there's a way for the script to then re-order those shape groups after generating them so the group created second is on top of the group created first?
I've tried things like the .moveToBeginning() method that works for layers, but no dice using that on a shape group (well, either that or I did something wrong which isn't out of the question).
Here's a demo code snippit that's been re-formatted to run on its own to show what I'm talking about/looking for:
app.beginUndoGroup("Shape Layer Example");
var curComp = app.project.activeItem;
var shapeLayer = curComp.layers.addShape();
shapeLayer.name = "Demo Shape Layer";
var shapeGroupRect = shapeLayer.property("Contents").addProperty("ADBE Vector Group"); //Create shape group
shapeGroupRect.name = "Rectangle";
var myRect = shapeGroupRect.property("Contents").addProperty("ADBE Vector Shape - Rect"); //add the rectangle to shape group
myRect.property("ADBE Vector Rect Size").setValue([500,500]);
var myRectFill = shapeGroupRect.property("Contents").addProperty("ADBE Vector Graphic - Fill");
myRectFill.property("ADBE Vector Fill Color").setValue([0,1,1]);
var shapeGroupCircle = shapeLayer.property("Contents").addProperty("ADBE Vector Group");
shapeGroupCircle.name = "Circle";
var myCircle = shapeGroupCircle.property("Contents").addProperty("ADBE Vector Shape - Ellipse");
myCircle.property("ADBE Vector Ellipse Size").setValue([500,500]);
var myCircleFill = shapeGroupCircle.property("Contents").addProperty("ADBE Vector Graphic - Fill");
myCircleFill.property("ADBE Vector Fill Color").setValue([1,0,1]);
//This is where I'd want to put something to re-arrange the two shape groups to put the circle on top of the rectangle so it renders on top
app.endUndoGroup();
Obviously the answer for the above snippit (and for my main script) is to just generate the shape that I want to be on top FIRST so it's on top from the start. This works correctly and is a solution, but it does make the organization of my main script a bit less nice to my brain. Basically, looking to see if there are extra steps I can take to re-organize the shape groups after generating them so I can keep my code organized in a way that I like.
Any insights the community has is appreciated! Thanks!
I think you just need to add this where your comment is at the end:
shapeGroupCircle.moveTo(1);
Copy link to clipboard
Copied
I think you just need to add this where your comment is at the end:
shapeGroupCircle.moveTo(1);
Copy link to clipboard
Copied
Aha!! I knew I was missing something simple. Thanks as always Dan, that works like a charm!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now