Skip to main content
SpencerCarpenter
Known Participant
January 19, 2016
Answered

Help with script

  • January 19, 2016
  • 1 reply
  • 547 views

Hi,

I'm just trying to create a script which automatically:

> Checks the selected layer is a target (or 2 node) camera

if yes then

>Creates a new 3d Null object [name = same as selected camera plus '_Target']

>Links the position of the selected camera's Point of Interest to the position of the new Null object

If anyone could help me to piece this together I would be very grateful.

Thanks

Spencer

This topic has been closed for replies.
Correct answer UQg

To know whether a camera is one-node or two-node is not completely obvious since there is no corresponding layer attribute.

But given that you want to put an expression in the poi property, you have to use canSetExpression and this sort of auto solves it.

If you have never scripted before, here's a sample code to build upon:

function campoi(){

    var comp = app.project.activeItem;

    if (!(comp instanceof CompItem)) return;

    var layers = comp.selectedLayers;

    var n, N=layers.length;

    var null3D;

    var num2NodesCams = 0;

    for (n=0; n<N; n++){

        if (layers instanceof CameraLayer && layers.transform.pointOfInterest.canSetExpression){

            // add a null, make it 3D

            null3D = comp.layers.addNull();

            null3D.threeDLayer = true;

            null3D.name = layers.name + "_Target";

        

            // add a poi expression

            layers.transform.pointOfInterest.expression = "thisComp.layer(\""+null3D.name+"\").transform.position";

        

            ++num2NodesCams;

            };

        };

    if (num2NodesCams===0){

        alert("Please select a two-node camera");

        };

    return;

    };

        

campoi();

Xavier

1 reply

UQg
UQgCorrect answer
Legend
January 19, 2016

To know whether a camera is one-node or two-node is not completely obvious since there is no corresponding layer attribute.

But given that you want to put an expression in the poi property, you have to use canSetExpression and this sort of auto solves it.

If you have never scripted before, here's a sample code to build upon:

function campoi(){

    var comp = app.project.activeItem;

    if (!(comp instanceof CompItem)) return;

    var layers = comp.selectedLayers;

    var n, N=layers.length;

    var null3D;

    var num2NodesCams = 0;

    for (n=0; n<N; n++){

        if (layers instanceof CameraLayer && layers.transform.pointOfInterest.canSetExpression){

            // add a null, make it 3D

            null3D = comp.layers.addNull();

            null3D.threeDLayer = true;

            null3D.name = layers.name + "_Target";

        

            // add a poi expression

            layers.transform.pointOfInterest.expression = "thisComp.layer(\""+null3D.name+"\").transform.position";

        

            ++num2NodesCams;

            };

        };

    if (num2NodesCams===0){

        alert("Please select a two-node camera");

        };

    return;

    };

        

campoi();

Xavier

SpencerCarpenter
Known Participant
January 19, 2016

Thanks very much for this I'll see if i can build upon it like you say. Much appreciated!!