Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Camera Swap Script Trouble

  • Camera Swap Script Trouble

    Posted by Mark Allen on January 26, 2009 at 12:52 am
    {
     // create undo group
    
      app.beginUndoGroup("Swap Camera Position");
    
      // select the active item in the project window
      
      alert("Make sure you have a comp selected and it is has a camera called Camera 1");
    
      // variable for the comp
    
      var activeComp = app.project.activeItem;
        
      var poiX = activeComp.layer("Camera 1").transform.pointOfInterest[0];
      var poiY = activeComp.layer("Camera 1").transform.pointOfInterest[1];
      var poiZ = activeComp.layser("Camera 1").transform.pointOfInterest[2];
      var camX = activeComp.layer("Camera 1").transform.position[0];
      var camY = activeComp.layer("Camera 1").transform.position[1];
      var camZ = activeComp.layer("Camera 1").transform.position[2];
      
       activeComp.layer("Camera 1").transform.position[0] = poiX;
       activeComp.layer("Camera 1").transform.position[1] = poiY;
       activeComp.layer("Camera 1").transform.position[2] = poiZ;
       activeComp.layer("Camera 1").transform.pointOfInterest[0] = camX;
       activeComp.layer("Camera 1").transform.pointOfInterest[1] = camY;
       activeComp.layer("Camera 1").transform.pointOfInterest[2] = camZ;
    
      app.endUndoGroup();
      }

    Okay – I’m new to writing scripts/expressions.. but I’m trying. I wanted a script that would swap the position and pointofinterest of my camera.

    At first I couldn’t get it to recognize the layer I had selected, but I think I got it to recognize a layer named Camera 1 at least, so I went with that – but… it doesn’t do anything. I know I must be assigning the position value incorrectly but after about six variations and a long internet search, I’m out of ideas… help appreciated, thank you.

    Mark Allen replied 17 years, 3 months ago 2 Members · 3 Replies
  • 3 Replies
  • Mark Allen

    January 26, 2009 at 1:06 am
     // create undo group
    
      app.beginUndoGroup("Swap Camera Position");
    
      // select the active item in the project window
      
      alert("Make sure you have a comp selected and it is has a camera called Camera 1");
    
      // variable for the comp
    
      var activeComp = app.project.activeItem;
        
      var poiX = activeComp.layer("Camera 1").transform.pointOfInterest[0];
      var poiY = activeComp.layer("Camera 1").transform.pointOfInterest[1];
      var poiZ = activeComp.layer("Camera 1").transform.pointOfInterest[2];
      var camX = activeComp.layer("Camera 1").transform.position[0];
      var camY = activeComp.layer("Camera 1").transform.position[1];
      var camZ = activeComp.layer("Camera 1").transform.position[2];
      
       activeComp.layer("Camera 1").transform.position.setValue([poiX, poiY, poiZ]);
       activeComp.layer("Camera 1").transform.pointOfInterest.setValue([camX, camY, camZ]);
    
      app.endUndoGroup();
      }

    Quick Update – I think this is maybe how setting the value is done, but it does not think my position information is a valid float now.

  • Dan Ebberts

    January 26, 2009 at 1:37 am

    Hi Mark,

    This should work:

    {
    // create undo group

    app.beginUndoGroup(“Swap Camera Position”);

    // select the active item in the project window

    alert(“Make sure you have the camera selected in the active comp”);

    // variable for the comp

    var activeComp = app.project.activeItem;
    var camLayer = activeComp.selectedLayers[0];

    var poi = camLayer.transform.pointOfInterest.value;
    var camPos = camLayer.transform.position.value;
    camLayer.transform.position.setValue(poi);
    camLayer.transform.pointOfInterest.setValue(camPos);

    app.endUndoGroup();
    }

    Dan

  • Mark Allen

    January 26, 2009 at 2:02 am

    Thanks, Dan. I will look through this to learn a bit.

    Seemed like a good script to learn from while being sort of useful (unless you count the time it took me trying to figure out how to write it. 🙂 )

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy