I would have preferred to solve this on my own, but I am running low on time so I hope I don't ask too many obvious questions.
I am new to scripts, but have completed almost 2 out of 4 scripts I will need for an upcoming project dealing with almost 2000 images.
What I am trying to do is:
1 Select layers from a PSD file.
2 Create a new folder for the new comps to be created from the PSD layers.
3 Create a new comp from from each layer, add a background layer (called BG) which is an already existing comp.
(4 Add a 3d text layer with a number representing the PSD layer's sequence number. This I believe I can figure out myself

My problems:
1 I can't add the "bg" layer to my new composition. I've tried .byName(bg) but it gives me error undefined
2 The new comps are not collected into my new folder. Strange things seem to happen. Sometimes the selected items end up in the new folder. Sometimes nothing happens.
3.. it tends to crash AeFx when I undo. (No big deal yet.. )
Could someone look at my script and point me in the right direction? (I have turned lines that don't work for me into comments)
Code: Select all
var proj = app.project;
var selection= proj.selection; // The selected items in the project panel
var amount= selection.length; // amount of comps selected
var folderYear = prompt("Folder name for image sequence year?", "1987"); // Name of the folder to be created __ Check so that this is a number (NaN)
var imageStart = prompt("What is the number of the first comp?", "1")
app.beginUndoGroup("batchCreate Comps");
alert(amount + " comps will be created in " + folderYear + " folder." +
"\n" + "\n" + "First Comp: " + imageStart + "\n" + "Last Comp: " + (imageStart-1+amount));
var compFolder = app.project.items.addFolder(folderYear); //creates a folder should be a string
for (i=1; i<= amount; i++){
var compName = (imageStart-1) + i; //increments the comp name
app.project.items.addComp(compName, 600, 600, 1, 60, 25); //creates a comp "name", width, height, pixelAspect, duration (seconds), frameRate (fps)
//app.project.item(compName).layers.byName("bg"); // should add excisting layer bg to the comp
app.project.item(compName).layers.add(selection[i-1]); //adds i of selected image sequence
//app.project.item(compName).parentFolder = compFolder;
}
app.endUndoGroup() // end UNDO GROUP