Page 1 of 1

Putting FootageItem into folders

Posted: April 4th, 2012, 2:54 pm
by ernpchan
I'm trying to organize comps and footage items into their own folders. The comps get put into the right folder. Not all the footage items do though. The code for each is pretty much the same except for different If conditions. Why do some footage items get properly moved and others dont?

Code: Select all

var compFolder = app.project.items.addFolder(asset);
var pngFolder = app.project.items.addFolder(asset + "_pngs");
pngFolder.parentFolder = compFolder;

for(var i = 1; i <= app.project.numItems; i++) {
if (app.project.item(i) instanceof CompItem && app.project.item(i).name != asset)
app.project.item(i).parentFolder = compFolder;
}

for(var i = 1; i <= app.project.numItems; i++) {
if (app.project.item(i) instanceof FootageItem)
app.project.item(i).parentFolder = pngFolder;
}

Re: Putting FootageItem into folders

Posted: April 5th, 2012, 2:01 am
by Paul Tuersley
My guess is that this could be due to the items' indexes changing when you move them. You're looping through app.project.items, but changing what's inside it during the loop. I'd suggest storing the item objects you find in another array and only moving them one you've looped through them all.

Re: Putting FootageItem into folders

Posted: April 7th, 2012, 11:25 am
by ernpchan
Thanks Paul. Turns out that's the problem. I came up with the same conclusion as you and everything is working perfectly now. Thx again.

Re: Putting FootageItem into folders

Posted: April 25th, 2012, 2:47 pm
by MYX_2000
Couldn't you also loop through last to first. This way the indexes always stay the same.

Re: Putting FootageItem into folders

Posted: April 25th, 2012, 3:03 pm
by ernpchan
MYX_2000 wrote:Couldn't you also loop through last to first. This way the indexes always stay the same.
Ah good idea. Thx.

Re: Putting FootageItem into folders

Posted: April 26th, 2012, 2:38 am
by Paul Tuersley
I have a feeling looping in reverse won't work here. That works in situations where you're looping through an index deleting things like keys, layers or footage, but in this case it is about moving things in the project window so I would think there's as much chance of messing things up if you loop through forwards or in reverse.

Re: Putting FootageItem into folders

Posted: April 26th, 2012, 8:18 am
by ernpchan
Good point.

Populating a second array definitely works. No point in messing with my script if it works. :D

Re: Putting FootageItem into folders

Posted: October 9th, 2012, 2:13 am
by Alan Eddie
You have to remember that a folder is considered an item too. When I was making TidyUp (script for putting stuff in folders, similar to what you are doing here). It took me an age to realize that the index count was actually changing in the project panel. I was assuming that folders were not objects or 'items' when I was sorting stuff.
Anyway you are right - best to build arrays and then sort.