Putting FootageItem into folders

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
ernpchan
Posts: 56
Joined: February 8th, 2010, 11:27 pm

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;
}
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

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.
ernpchan
Posts: 56
Joined: February 8th, 2010, 11:27 pm

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.
MYX_2000
Posts: 12
Joined: February 6th, 2012, 2:01 pm

Couldn't you also loop through last to first. This way the indexes always stay the same.
ernpchan
Posts: 56
Joined: February 8th, 2010, 11:27 pm

MYX_2000 wrote:Couldn't you also loop through last to first. This way the indexes always stay the same.
Ah good idea. Thx.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

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.
ernpchan
Posts: 56
Joined: February 8th, 2010, 11:27 pm

Good point.

Populating a second array definitely works. No point in messing with my script if it works. :D
Alan Eddie
Posts: 30
Joined: January 12th, 2012, 1:36 am
Location: Ireland
Contact:

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.
Alan Eddie
_______________________
www.alaneddie.com
3d Animation and VFX
RTE
Dublin
Post Reply