Snippets

Kyle Martinez AE Script: Move to Midpoint

Created by Kyle Martinez
(function() {
    try {
        app.beginUndoGroup("Move to Midpoint");
        var comp = app.project.activeItem;
        var selectedLayers = comp.selectedLayers;
        var layerOne = selectedLayers[0];
        var layerTwo = selectedLayers[1];
        var x = (layerOne.transform.position.value[0] + layerTwo.transform.position.value[0]) / 2;
        var y = (layerOne.transform.position.value[1] + layerTwo.transform.position.value[1]) / 2;
        var targetLayer = selectedLayers[2];
        targetLayer.transform.position.setValue([x,y]);
    } catch (err) {
        alert(err);
    } finally {
        app.endUndoGroup();
    }
})();

Comments (0)