for some reason my loop is only going through once despite importedChar.numItems =2
After effects item start on 1 instead of 0, so I use x=1, Here’s what I have
for(x=1; x < importedChar.numItems; x++) {
if (importedChar.item(x) instanceof CompItem) {
//Add imported Char to Main Comp
var newObj = null;
var newObj = myComp.layers.add(importedChar.item(x))
//Move Layer under null
newObj.moveAfter(newNull);
//Parent to Null
newObj.parent = newNull;
}
}
If the first item is a composition it runs fine, but leaves the loop if it’s the second
You need to use
<=instead of<to get it to run twice.Edit: Alternatively,
for(x=0; x < importedChar.numItems; x++) {and then usex+1when you need to use it, but in situations where you can avoid that,<=is preferable.Situations when you’d want the alternative usually arise when you need to access an index and a meaningful value (e.g. to print a human-friendly error message)