Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding a Camera and Orbit Null with Extendscript

Community Beginner ,
Sep 13, 2017 Sep 13, 2017

Hey Guys,

Total Noob to all this scripting stuff, but I'm loving it so far!

I've got a problem where, I'm using the following to try and add a camera to my comp:

var myComp = app.project.activeItem;

var myLayers = myComp.layers;

app.beginUndoGroup("New Cam");

myLayers.addCamera("cam", [0,0]);

myLayers.addNull();

myComp.layer(1).name = "CAM_NULL";

myComp.layer(2).parent = myComp.layer(1);

app.endUndoGroup();

The problem I'm having is that when I just add a camera and a null using the UI, they are set up all centred nice and the other layers in my scene don't change. But, when I use my script, it seems like all of the layers in my comp shift to the right and down. I'm noticing this is because when I add the camera using the script, the Point of Interest and Position values for the camera go from (0,0,0) to (-960, -540, 0) when they get parented to the CAM_NULL. 😕

Anyhow, any input as to why this might be happening?

TOPICS
Scripting
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Sep 14, 2017 Sep 14, 2017

Hi Atekker

No worries, it's a simple fix.

It didn't run because I assigned my composition to a variable "comp" and you assigned it to "myComp".

To fix that you need to fix two lines of your code:

myCam.property("ADBE Transform Group").property("ADBE Position").setValue([comp.width/2, comp.height/2,negZoom]); //if you run the script from Extend Script before fixing, you will see at bottom left "comp is undfined". This is your clue that the variable does not exist. In this line replace comp with myCom

...
Translate
Participant ,
Sep 14, 2017 Sep 14, 2017

You need to adjust the camera after adding it to your comp.

//Assign it to a variable first

var myCam = myLayers.addCamera("cam", [0,0]);

//Then get the zoom value for you camera and invert it

var negZoom = -myCam.property("ADBE Camera Options Group").property("ADBE Camera Zoom").value;

// set your camera position

myCam.property("ADBE Transform Group").property("ADBE Position").setValue([comp.width/2, comp.height/2,negZoom]);

//set your camera point of interest

myCam.property("ADBE Transform Group").property("ADBE Anchor Point").setValue([comp.width/2, comp.height/2,0]);

then add null and parent it. Should be all good then.

Let me know it works.

Cheers

Henrique

Henrique \\ TMMW
Clips Exporter | Text Replacer | Selector for Premiere Pro | Thumbs Up
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 14, 2017 Sep 14, 2017

Hey Henrique,

Thanks for getting back to me so quick!

I modified my code to read as follows:

var myComp = app.project.activeItem;

var myLayers = myComp.layers;

app.beginUndoGroup("New Cam");

var myCam = myLayers.addCamera("Cam", [0,0]);

var negZoom = -myCam.property("ADBE Camera Options Group").property("ADBE Camera Zoom").value;

myCam.property("ADBE Transform Group").property("ADBE Position").setValue([comp.width/2, comp.height/2,negZoom]);

myCam.property("ADBE Transform Group").property("ADBE Anchor Point").setValue([comp.width/2, comp.height/2,0]);

myComp.layers.addNull();

myComp.layer(1).name = "CAM_NULL";

myComp.layer(2).parent = myComp.layers.byName("CAM_NULL");

app.endUndoGroup();

...but it seems to just stall after it adds the Camera layer. I don't get any error pop ups and the undo function works as intended, but there doesn't seem to be any changes to the camera properties and the addNull doesn't happen at all.

I thought there might be some issue with one of the properties being "Point of Interest" instead of "Anchor Point", but it doesn't work if I make that change either.

Weird.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 14, 2017 Sep 14, 2017

Hi Atekker

No worries, it's a simple fix.

It didn't run because I assigned my composition to a variable "comp" and you assigned it to "myComp".

To fix that you need to fix two lines of your code:

myCam.property("ADBE Transform Group").property("ADBE Position").setValue([comp.width/2, comp.height/2,negZoom]); //if you run the script from Extend Script before fixing, you will see at bottom left "comp is undfined". This is your clue that the variable does not exist. In this line replace comp with myComp.

myCam.property("ADBE Transform Group").property("ADBE Anchor Point").setValue([comp.width/2, comp.height/2,0]); //same here

Then it should be all good.

Let me know if it works now.

Cheers

Henrique

Henrique \\ TMMW
Clips Exporter | Text Replacer | Selector for Premiere Pro | Thumbs Up
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 16, 2017 Sep 16, 2017
LATEST

That did it! Thanks so much Henrique! I really appreciate your help!

Alex

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines