Last active
August 20, 2022 06:11
-
-
Save aescripts/e4eca4de305723cf1b0f95821ee48f22 to your computer and use it in GitHub Desktop.
#AfterEffects #Script #KBar #Scriptlet Move Layer XYZ
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 scriptlet | |
// v1.2 | |
// 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 | |
// 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) { | |
moveLayerKBarScriptlet(); | |
} 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 moveLayerKBarScriptlet() { | |
//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"); | |
var myLayer; | |
for (var h = 0; h < myComp.selectedLayers.length; h++) { | |
myLayer = myComp.selectedLayers[h]; | |
if (myLayer.position.numKeys > 0) { | |
for (var i = 1; i <= myLayer.position.numKeys; i++) { | |
myLayer.position.setValueAtTime(myLayer.position.keyTime(i), myLayer.position.keyValue(i) + 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