Page 1 of 1

Accessing AVLayers

Posted: August 28th, 2009, 4:49 am
by shapeOfMotion
Hi !

I need to access AV Layers in a comp. I use the following code to create a parent composition with a child comp inside it.

Code: Select all


{

	var myProject = app.project; // declare the project name
	var myComp = myProject.activeItem; // declare the comp name
	
	var myParentComp;
	var myParentCompName = "parentComp";
	var myParentCompWidth= 960;
	var myParentCompHeight = 360;
	var myParentCompPixelAspect = 1;
	var myParentCompDuration = 5;
	var myParentCompFramerate = 25;
		
	createParentComp(); // create the main comp
	createChildComp(); // create sub comp;

	function createParentComp()
	{
		myParentComp = app.project.items.addComp(myParentCompName,myParentCompWidth,myParentCompHeight,myParentCompPixelAspect,myParentCompDuration,myParentCompFramerate);	
	}

	function createChildComp()
	{
		var myChildCompName = "childComp";
		var myChildCompWidth= myParentComp.width*.5;
		var myChildCompHeight = myParentComp.height*.5;
		
		// create child comp
		var newComp = app.project.items.addComp(myChildCompName,myChildCompWidth,myChildCompHeight,myParentCompPixelAspect,myParentCompDuration,myParentCompFramerate);	

		// add child to mainComp
		var myLayer = myParentComp.layers.add(newComp); 

	}
}

That works fine. I´ve looked in the afx scripting guide and found this:

Code: Select all


app.project.item(index).layer(index);

That seems to be the way to acces the layer in a comp. But I don´t get it to work.
to get the layer index and item index I tried:
( I got an error when trying to get the .index property of "myMainComp )

Code: Select all

var myLayerIndex = myLayer.index;
var myMainId = myMainComp.id;
I´m really new to scripting for afx so I would appreciate all the coments and tips I could get !

Thanks alot,

- J

Re: Accessing AVLayers

Posted: August 28th, 2009, 5:37 pm
by nab
Define the "myLayer" variable outside the function, or modify the function so that it returns the created layer.