Created
February 27, 2020 15:07
-
-
Save aescripts/eba1792e17ed7d2aff0eda0fb25113d5 to your computer and use it in GitHub Desktop.
#AfterEffects #Script #KBar #Scriptlet Move Layer XYZ at CTI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// move layer xyz at CTI scriptlet | |
// v1.0 | |
// Lloyd Alvarez https://aescripts.com/ | |
// | |
// Works in KBar as a JSX or Scriptlet with an argument X,Y,Z (Z is optional) to move the selected layers by that amount at the current time marker (CTI) | |
// For example: 10,20,-30 | |
// Would move the selected layer 10 pixel in X, 20 in y and -30 in z | |
// If no argument is set then it will prompt for it | |
var isKBarRunning = (typeof kbar !== 'undefined'); | |
if (isKBarRunning && kbar.button && kbar.button.argument) { | |
var moveLayerKbarArgument = kbar.button.argument; | |
delete kbar.button; | |
} | |
if (moveLayerKbarArgument == undefined) { | |
moveLayerKbarArgument = ""; | |
} | |
if (isKBarRunning) { | |
moveLayerAtCtiKBarScriptlet(); | |
} else { | |
alert("This tool is only intended to work when launched from KBar or a tool using the KBar api\nhttps://bitbucket.org/kraftyfx/kbar/wiki/Buttons/Scriptlet"); | |
} | |
function moveLayerAtCtiKBarScriptlet() { | |
//defaults | |
var moveAmount = moveLayerKbarArgument.toString(); | |
if (moveAmount == "") { | |
moveAmount = prompt("Please enter how much to move in this format: X,Y,Z (Z is optional)", ""); | |
if (moveAmount == "") { | |
return; | |
} | |
} | |
moveAmount = moveAmount.replace(/\s+/g, "").split(","); // [x,y,z] | |
if (moveAmount.length == 0 || moveAmount.toString() == "") { | |
alert("Please enter a valid amount in format X,Y,Z (Z is optional)"); | |
return; | |
} | |
if (!isKBarRunning) { | |
alert("This tool is only intended to work when launched from KBar"); | |
return; | |
} | |
var myComp = app.project.activeItem; | |
if (!(myComp instanceof CompItem) || myComp.selectedLayers == null || myComp.selectedLayers.length < 1) { | |
alert("Please select a layer to move"); | |
return; | |
} | |
app.beginUndoGroup("Move Layer XYZ at CTI"); | |
var myLayer; | |
var myTime = myComp.time; | |
for (var h = 0; h < myComp.selectedLayers.length; h++) { | |
myLayer = myComp.selectedLayers[h]; | |
if (myLayer.position.numKeys > 0) { | |
myLayer.position.setValueAtTime(myTime, myLayer.position.valueAtTime(myTime,false) + moveAmount); | |
} else { | |
myLayer.position.setValue(myLayer.position.value + moveAmount); | |
} | |
} | |
app.endUndoGroup(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment