var fileList = app.document.selections;
for(var i=0; i<fileList.length; i++){
myBTalk(fileList[i].path);
}
function myBTalk(filename){
var scriptcode = 'var opt = new ImportOptions();';
scriptcode += 'opt.file = new File("'+filename+'");';
scriptcode += 'app.project.importFile(opt);';
$.writeln(scriptcode);
var btObj = new BridgeTalk;
btObj.body = scriptcode;
btObj.target = "aftereffects-8";
btObj.send();
}
myBTalk(app.document.selections);
function myBTalk(fileList){
var scriptcode = 'var fileList = [';
for(var i=0; i<fileList.length; i++){
scriptcode += '"'+fileList[i].path+'"';
if (i != fileList.length-1) scriptcode += ',';
}
scriptcode +='];';
scriptcode +='var myFolder = makeFolder(fileList[0]);';
scriptcode +='for(var i=0; i<fileList.length; i++){';
scriptcode +='var opt = new ImportOptions();';
scriptcode +='opt.file = new File(fileList[i]);';
scriptcode +='app.project.importFile(opt).parentFolder = myFolder;';
scriptcode +='};';
scriptcode +='function makeFolder(path){';
scriptcode +='var fd = path.split("/");';
scriptcode +='var pFolder = itemFolder = app.project.items.addFolder(fd[fd.length-2]);';
scriptcode +='for(var i=fd.length-3; i>0; i--){';
scriptcode +='var subFolder = app.project.items.addFolder(fd[i]);';
scriptcode +='pFolder.parentFolder = subFolder;';
scriptcode +='pFolder = subFolder;';
scriptcode +='}';
scriptcode +='return itemFolder;';
scriptcode +='}';
$.writeln(scriptcode);
var btObj = new BridgeTalk;
btObj.body = scriptcode;
btObj.target = "aftereffects-8";
btObj.send();
}