Skip to content

Instantly share code, notes, and snippets.

@dokluch
Last active August 29, 2015 14:03
Show Gist options
  • Save dokluch/830e93ae96e841d65f58 to your computer and use it in GitHub Desktop.
Save dokluch/830e93ae96e841d65f58 to your computer and use it in GitHub Desktop.
//CC-BY Nik Ska, 2014
var sel = app.project.selection; //selected
var used = []; //these were used
app.beginUndoGroup("Precomping as hell");
var precompFolder = app.project.items.addFolder("Precomps");
for(var c = 1; c <= Math.ceil(sel.length/10); c++){
//creating comps
var newComp = app.project.items.addComp("Precomp " + c, sel[0].width, sel[0].height, sel[0].pixelAspect, sel[0].duration, sel[0].frameRate);
newComp.parentFolder = precompFolder;
var count = 1;
while(count <= 10){
var r = Math.floor(Math.random()*sel.length); //random num
if(!used.isThere(r)){ //if this number hasn't been used
newComp.layers.add(sel[r]); //add the corresponding comp to precomp
used.push(r); //mark it as used
count++;
}
}
}
app.endUndoGroup();
Array.prototype.isThere = function(el){
for(var i = 0; i<this.length; i++){
if(this[i] === el) return true
}
return false
}
@dokluch
Copy link
Author

dokluch commented Jun 29, 2014

  1. Select N comps, where N is divisible by 10
  2. Script creates N/10 precomps
  3. Each precomp contains 10 random unique selected comps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment