Page 1 of 1

Duplicate a layer and a camera and do stuff individually?

Posted: December 27th, 2010, 6:25 am
by Simma
Hi all,

I'm trying to write a script that will (among other stuff) duplicate my selected layers, which is a camera layer and a footage layer. Then I would like to to do different things to them, say adjust the position of the camera and adjust the rotation of the footage. I think I can find the duplicate part, but could anyone point me in the right directio how to "seperate" camera layers from footage layers so I can assign stuff to them individually?

Re: Duplicate a layer and a camera and do stuff individually

Posted: December 27th, 2010, 8:51 am
by lloydalvarez
Hi Simma,

Layers are objects so you can test to see if they are instanceof's known objects like this:

Code: Select all

var selLayers=app.project.activeItem.selectedLayers;

for (var i=0; i<selLayers.length;i++){
    if(selLayers[i] instanceof CameraLayer) alert("Layer: \""+selLayers[i].name+"\" is a camera");
    if(selLayers[i] instanceof AVLayer) alert("Layer: \""+selLayers[i].name+"\" is an AV layer");
    }
-Lloyd

Re: Duplicate a layer and a camera and do stuff individually

Posted: December 27th, 2010, 8:52 am
by lloydalvarez
btw, to figure out what the object name to test against is, just do an alert on the layer and it will tell you what it is within brackets like this: [AVLayer]

Keep in mind that these are case-sensitive.

-Lloyd

Re: Duplicate a layer and a camera and do stuff individually

Posted: December 28th, 2010, 4:02 am
by Simma
Thank you Lloyd, you (and this site) is very helpful. I did search for info about this but couldn't find any.

Don't know if this is correct, but it worked for me;

Code: Select all


var selLayers = app.project.activeItem.selectedLayers;

for (var i=0; i<selLayers.length;i++)
    if(selLayers[i] instanceof CameraLayer){
   var myCamera = selLayers[i]
   var dupCamera = myCamera.duplicate();
    
   
} else {
    var myLayer = selLayers[i]
    var dupLayer = myLayer.duplicate();

 }