It’s possible to give a uniform treatment to layers and items since they belong to a collection, but there is no seach thing as a PropertyCollection, so that properties/propertyGroups would have to be handled differently.
For instance i do use something like your spider object, and it is organized like this:
var $coll = {
forEach : function forEach(coll, callback){
var n, N=coll.length;
for (n=1; n<=N; n++){
callback(coll[n], n, coll);
};
return;
},
find : function find(coll, filter){
var n, N=coll.length;
if (filter(coll[n], n, coll)) return coll[n];
},
return null;
},
indexOf : function indexOf(coll, x){
var n, N=coll.length;
for (n=1; n<=N; n++){
if (coll[n]==x) return n;
},
return 0;
},
// etc,, etc
};
So $coll.forEach would be the equivalent of your spider.crawl
I find it usefull too, so you can write things like :
var footageFolder = $coll.find(app.project.items, function(element, index, collection){return element.name === “Footage” && element.typeName === “Folder”;}) || app.project.items.addFolder(“Footage”);
(this searches a folder called “Footage” and creates it if not found).
But as soon as recursions are involved i found it a lot clearer to write full code, since there are many ways to recurse through a folder architecture.
Here is a very basic starting block to import and then create.
It only import basic footage (image, video) and creates comps at a fixed size/duration (not based on content!).
It would require quite a lot of work to turn it ito what you actually want, but it can help to start with:
function recursiveImport(sysFolder, aeFolder){
// create a AE folder and parent it to aeFolder:
var folder = app.project.items.addFolder(sysFolder.name);
folder.parentFolder = aeFolder || app.project.rootFolder;
var files = sysFolder.getFiles();
var n, N=files.length;
for (n=0; n<=N; n++){
if (files[n] instanceof Folder){
recursiveImport(files[n], folder);
}
else{
try{app.project.importFile(new ImportOptions(files[n])).parentFolder = folder;}catch(e){};
};
};
return folder;
};
function recursiveCreate(aeFootageFolder, aeCompFolder, compSpec){
var N=aeFootageFolder.items.length, n, item;
var comp = aeCompFolder.items.addComp(aeFootageFolder.name, compSpec.width, compSpec.height, compSpec.pixelAspect, compSpec.duration, compSpec.frameRate);
for (n=N; n>0; n--){
item = aeFootageFolder.items[n];
if (item instanceof FolderItem){
comp.layers.add(recursiveCreate(item, aeCompFolder.items.addFolder(item.name), compSpec));
}
else{
comp.layers.add(item);
};
};
return comp;
};
(function(){
var sysFolder = Folder.selectDialog();
if (!sysFolder) return;
var allFootageFolder = $coll.find(app.project.items, function(element, index, collection){return element.name === "Footage" && element.typeName === "Folder";}) || app.project.items.addFolder("Footage");
var thisFootageFolder = recursiveImport(sysFolder, allFootageFolder);
var allCompFolder = $coll.find(app.project.items, function(element, index, collection){return element.name === "Comps" && element.typeName === "Folder";}) || app.project.items.addFolder("Comps");
var thisCompFolder = allCompFolder.items.addFolder(thisFootageFolder.name);
var compSpec = {
width : 1280,
height : 720,
pixelAspect : 1.0,
duration : 10,
frameRate : 25
};
recursiveCreate(thisFootageFolder, thisCompFolder, compSpec);
return;
})();
Xavier.
Edit: tried to correct the <= bugs, if failed again i give up.