ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

how to keep all shapes in the same shape layer? after effects scripts

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Eran Peled
how to keep all shapes in the same shape layer? after effects scripts
on Feb 8, 2017 at 10:33:45 pm

hello, i made an UI script, and the user should run the funcion (same button) few times, one after the another, with diffrent values. for now every time the user click the button the funcion do something and as well create a new shape layer each time. but i want to keep all shapes inside the same layer.

here is part of the funcion, i deleted the other stuff the funcion do which not relative for the shapes.


thanks!!

myPanel.grp.groupThree.otherPoints.onClick = function() {
app.beginUndoGroup("Other Points");
var myComp = app.project.activeItem;
var shapeLayer = myComp.layers.addShape();
var shapeGroup = shapeLayer.property("ADBE Root Vectors Group");
shapeGroup.addProperty("ADBE Vector Shape - Rect");
shapeGroup.addProperty("ADBE Vector Graphic - Fill");
shapeGroup.property("ADBE Vector Shape - Rect")("ADBE Vector Rect Size").setValue([30,30]);
shapeGroup.property("ADBE Vector Shape - Rect")("ADBE Vector Rect Position").setValue([-960+curXpos,-540+avgCurY]);
app.endUndoGroup();
}


Return to posts index

Dan Ebberts
Re: how to keep all shapes in the same shape layer? after effects scripts
on Feb 9, 2017 at 12:15:09 am

I haven't tested this, but if you replace this line:

var shapeLayer = myComp.layers.addShape();

with something like this:


var shapeLayer = null;
for (var i = 1; i <= myComp.numLayers; i++){
if (myComp.layer(i) instanceof ShapeLayer){
shapeLayer = myComp.layer(i);
break;
}
}
if (shapeLayer == null){
shapeLayer = myComp.layers.addShape();
}


it should add the shape to the first shape layer it finds.


Dan



Return to posts index

Eran Peled
Re: how to keep all shapes in the same shape layer? after effects scripts
on Feb 9, 2017 at 12:41:05 am

thanks
but its just not doing anything, not creating a shape or anything else.
i will include your code with mine, that you will see how i wrote it:

app.beginUndoGroup("Other Points");
var myComp = app.project.activeItem;

var shapeLayer = null;
for (var i = 1; i &lt;= myComp.numLayers; i++){
if (myComp.layer(i) instanceof ShapeLayer){
shapeLayer = myComp.layer(i);
break;
}
}
if (shapeLayer == null){
shapeLayer = myComp.layers.addShape();
}
var shapeGroup = shapeLayer.property("ADBE Root Vectors Group");
shapeGroup.addProperty("ADBE Vector Shape - Rect");
shapeGroup.addProperty("ADBE Vector Graphic - Fill");
shapeGroup.property("ADBE Vector Shape - Rect")("ADBE Vector Rect Size").setValue([30,30]);
shapeGroup.property("ADBE Vector Shape - Rect")("ADBE Vector Rect Position").setValue([0,0]);
app.endUndoGroup();


Return to posts index


Dan Ebberts
Re: how to keep all shapes in the same shape layer? after effects scripts
on Feb 9, 2017 at 12:50:09 am

That's strange. It works for me--it creates a shape layer is there isn't one, or adds a little red square to the first one it finds.

Dan



Return to posts index

Eran Peled
Re: how to keep all shapes in the same shape layer? after effects scripts
on Feb 9, 2017 at 12:53:41 am

sorry, it is working , THANKS.
but only the last Button click on (as the user can put values and click again and again)
only the last button click, set the real value of the size and position, and the rest are on default values


Return to posts index

Eran Peled
Re: how to keep all shapes in the same shape layer? after effects scripts
on Feb 9, 2017 at 3:45:02 am

it should be written like this to work properly (of course set position as you like or all be in same spot):

app.beginUndoGroup("Other Points");
var myComp = app.project.activeItem;

var shapeLayer = null;
for (var i = 1; i &lt;= myComp.numLayers; i++){
if (myComp.layer(i) instanceof ShapeLayer){
shapeLayer = myComp.layer(i);
break;
}
}
if (shapeLayer == null){
shapeLayer = myComp.layers.addShape();
}
var shapeGroup = shapeLayer.property("Contents").addProperty("ADBE Vector Group");
shapeGroup.property("Contents").addProperty("ADBE Vector Shape - Rect");
shapeGroup.property("Contents").addProperty("ADBE Vector Graphic - Fill");
shapeGroup.property("Contents").property("ADBE Vector Shape - Rect")("ADBE Vector Rect Size").setValue([30,30]);
shapeGroup.property("Contents").property("ADBE Vector Shape - Rect")("ADBE Vector Rect Position").setValue([0,0]);
app.endUndoGroup();


Return to posts index

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