Skip to main content
Known Participant
October 12, 2019
Question

Make a script to position anchor point

  • October 12, 2019
  • 2 replies
  • 3550 views

Hi 🙂 

I want to make a script to move the anchor point of a selected solid to the top left. how can I do that?

 

I have this function to center it but dont know how to convert it to the top left

function centerAnchorPoint( layer ){  
      
    var comp = layer.containingComp;  
    var curTime = comp.time;  
    var layerAnchor = layer.anchorPoint.value;  
      
    /* find center by bounding box of the layer */  
    var x = layer.sourceRectAtTime(curTime, false).width/2;  
    var y = layer.sourceRectAtTime(curTime, false).height/2;  
    
    var xAdd = (x-layerAnchor[0]) * (layer.scale.value[0]/100);  
    var yAdd = (y-layerAnchor[1]) * (layer.scale.value[1]/100);  
      
    /* set new anchor point*/  
    layer.anchorPoint.setValue([ x, y ]);  
      
    var layerPosition = layer.position.value;  
      
    /* fix position with adjustments */  
    layer.position.setValue([ layerPosition[0] + xAdd, layerPosition[1] + yAdd, layerPosition[2] ]);  
      
      
      
      
}; 
    
This topic has been closed for replies.

2 replies

Dan Ebberts
Community Expert
Community Expert
October 12, 2019

Just change these two lines:

 

var x = layer.sourceRectAtTime(curTime, false).width/2;
var y = layer.sourceRectAtTime(curTime, false).height/2;

 

to this:

 

var x = 0;
var y = 0;  

 

Dan

Mylenium
Legend
October 12, 2019

The scale is irrelevant. The anchor point is the transform center of the source footage item, not some abstract separate entity applied after the fact. The rest is just a case of subtracting rather than adding.

 

Mylenium