Forums › Adobe After Effects Expressions › Shift-Parent Script: Modification-Advice needed
Shift-Parent Script: Modification-Advice needed
Michael Schneider
November 29, 2019 at 11:57 pmI need to Shift-parent nearly 100 images to the same number of shape layers, so that the images adopt the position values of the shape layers. I found this great script by Nik Ska: https://github.com/ae-scripting/scripting-snippets/blob/master/batchParent.jsx that basically does what I need, but without the Shift-part..
Does anyone know how to adapt the script for Shift-parenting needs?
Thanks in advance and best wishes from Germany,
Michael//Batch parent layers
//1. select the batch you want to set parents to
//2. select the batch you want to parentthe first batch to//order matters
//0.1 - initial release
//CC-BY-SA, Nik Ska, 2013
var nsBatchParent = this;
this.version = 0.1;
this.scriptTitle = "Batch Parent";nsBatchParent.run = function(){
this.buildGUI(this);
}nsBatchParent.thisBatch = [];
nsBatchParent.thatBatch = [];nsBatchParent.buildGUI = function(thisObj){
thisObj.w = (thisObj instanceof Panel) ? thisObj : new Window("palette", thisObj.scriptTitle, undefined, {resizeable:true});
thisObj.w.alignChildren = ['left', 'top']var l1 = thisObj.w.add("group{orientation:'row', alignChildren: ['left', 'top']}");
l1.add("staticText", undefined, "Parent");
l1.margins = [0,0,0,0];
var thisBttn = l1.add("button", undefined, "this");
thisBttn.size = [40, 20];var l2 = thisObj.w.add("group{orientation:'row', alignChildren: ['left', 'top']}");
var toTxt = l2.add("staticText", undefined, " to");
toTxt.size = [33,20];
l2.margins = [0,0,0,0];
var thatBttn = l2.add("button", undefined, "that");
thatBttn.size = [40, 20];thisBttn.onClick = function(){
thisObj.getThis(thisObj);
}thatBttn.onClick = function(){
thisObj.getThat(thisObj);
}if (thisObj.w instanceof Window){
thisObj.w.center();
thisObj.w.show();
}
else thisObj.w.layout.layout(true);
}nsBatchParent.getThis = function(thisObj){
var activeComp = app.project.activeItem;
if(activeComp && activeComp instanceof CompItem){
if(activeComp.selectedLayers.length){
thisObj.thisBatch = activeComp.selectedLayers;
}
else alert("Select at least one layer")
}
}nsBatchParent.getThat = function(thisObj){
var activeComp = app.project.activeItem;
if(activeComp && activeComp instanceof CompItem){
if(activeComp.selectedLayers && activeComp.selectedLayers.length === thisObj.thisBatch.length){
thisObj.thatBatch = activeComp.selectedLayers;
thisObj.parentShit(thisObj);
}
else alert("Select the same amount of layers: " + thisObj.thatBatch.length)
}
}nsBatchParent.parentShit = function(thisObj){
app.beginUndoGroup("Batch Parenting");
for(var i = 0; i < thisObj.thisBatch.length; i++){
if(thisObj.thisBatch[i]!=thisObj.thatBatch[i]){
thisObj.thisBatch[i].parent = thisObj.thatBatch[i];
}
}
app.endUndoGroup();}
nsBatchParent.run();
Michael Schneider
December 1, 2019 at 10:24 amFor all of you that might haven’t learned about Shift-Parenting yet or maybe forgot about it, here’s a great explainer by ukramedia:
https://www.youtube.com/watch?v=VTSczD0U47g
It really can be incredibly useful in certain scenarios.Some contents or functionalities here are not available due to your cookie preferences!This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.
Log in to reply.