-
AE script to create solids and automatically parent them to a null.
Hello,
I’m quite new to expressions/scripting.
I’m trying to write an AE .jsx script to create a scene which automatically creates a comp, generates many solids and places them (by 3D rotations) around a central origin to create the population of people standing on a planet.
Also in the script I create a null at the centre of the planet.My script works so far and generates all of the 3D layers, it also generates the Null and even a camera for the scene.
But I can’t seem to write the script which automatically parents all of the solids to the null object. I.e. I’m dynamically generating the layers but unable to dynamically link them up to the null from within my .jsx code.
The problem is right at the end of the script, here…
// connect new solid to null at planet centreAny help would be very gratefully received, with thanks, Chris
{// Create script undo group
app.beginUndoGroup("Create Square");
// create project if necessary
var proj = app.project;
if(!proj) proj = app.newProject();// create new comp named 'my comp'
var compW = 1920; // comp width
var compH = 1080; // comp height
var compL = 15; // comp length (seconds)
var compRate = 25; // comp frame rate
var compBG = [48/255,63/255,84/255] // comp background colorvar myItemCollection = app.project.items;
var myComp = myItemCollection.addComp('my comp',compW,compH,1,compL,compRate);
myComp.bgColor = compBG;//create camera
var w = myComp.width /2 ;
var h = myComp.height /2 ;
var newCamera = myComp.layers.addCamera("New Camera",[w,h]);
newCamera.position.setValue([w,h,-2500]);//create null
var myNull = myComp.layers.addNull();
myNull.threeDLayer = true;//set planet radius
var planetRadius=400;// for loop to create multiple solids
var totalCount=50;
for (i=1; i<=totalCount; i++)
{var randomnumber=Math.floor(Math.random()*361)
// create new solid named "my square"
var manXsize=20;
var manYsize=58;
var mySolid = myComp.layers.addSolid([1.0,1.0,0], "man"+i, manXsize, manYsize, 1, compL);
mySolid.threeDLayer = true;// place anchor point at base of solid + planetRadius
mySolid.property("anchorPoint").setValue([manXsize/2,manYsize+planetRadius,0]);// 3D rotations on the solids
mySolid.property("rotationY").setValue([randomnumber]);
mySolid.property("rotationZ").setValue([360*i/totalCount]);// connect new solid to null at planet centre
myComp.layer(i).parent.setValue(myNull);}
app.endUndoGroup();}