Skip to content

Instantly share code, notes, and snippets.

@Hoikohroh
Created July 15, 2015 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hoikohroh/3785f4b044d7d3b5678b to your computer and use it in GitHub Desktop.
Save Hoikohroh/3785f4b044d7d3b5678b to your computer and use it in GitHub Desktop.
Adobe AfterEffects script (JSX):Z_scale
/*
Adobe AfterEffects Script (JSX)
Z_scale
v20150716
*/
////////////////////////////////variable declaration////////////////////////////////
var thisComp= app.project.activeItem;
var selectedLayers= new Array();
var thisLayer = null;
var distance,newScale,cam,CamP,CamZ;
var thisW,thisH,newCamera;
////////////////////////////////body////////////////////////////////
app.beginUndoGroup("FitToComp_offsetZ");
if(thisComp instanceof CompItem){
selectedLayers = thisComp.selectedLayers;
if(selectedLayers.length > 0){
cam = thisComp.activeCamera;
if (cam == null){
createCam();
cam = thisComp.activeCamera;
};
CamP = cam.position.value[2];
CamZ = cam.Zoom.value;
for(i=0; i < selectedLayers.length; i++){
thisLayer = selectedLayers[i];
if (thisLayer.threeDLayer){
adjustScale(thisLayer,CamP,CamZ);
};
};
} else {
alert('unselected layer');
};
} else {
alert('unselected compositon');
};
app.endUndoGroup();
////////////////////////////////functions////////////////////////////////
function adjustScale(Lay,ValP,ValZ){
distance = Lay.Position.value[2] - ValP;
newScale = (distance / ValZ) * 100;
Lay.scale.setValue([newScale,newScale,newScale]);
};
function createCam()
{
app.beginUndoGroup("Create Camera");
thisW = thisComp.width /2 ;
thisH = thisComp.height /2 ;
newCamera = thisComp.layers.addCamera("camera", [thisW,thisH]);
newCamera.Position.setValue([thisW,thisH,newCamera.Position.value[2]]);
app.endUndoGroup();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment