Quantcast
Channel: Adobe Community : Discussion List - After Effects Scripting
Viewing all articles
Browse latest Browse all 2143

Importing files that don't already exist in the project.

$
0
0

Hi,

I'm currently trying to write a script that will import any files from a given location that can't already be found in the After Effects project. I'm very new to scripting so apologies any incorrect terminology or poor etiquette. This kind of does the job but I think there must be simpler, more streamlined and more correct ways of doing.

 

I've been struggling to deal with undefined elements and .DS_Store (mac) files so any help here would be much appreciated.

 

This is what I have so far ...

var numItems = app.project.numItems;

 

var targetFolder = Folder("~/Desktop/TEST/"); // folder path

var files = targetFolder.getFiles();

var filesNum = files.length;

 

var importArray = [];

var newImportArray = [];

var uniqueImportArray = [];

 

for(var i = 1; i <= numItems; i++){

    importArray.push(app.project.item(i).name);

    }

   

    for(var s = 0; s < filesNum; s++){

        importArray.push(files[s].name);

                }

 

Array.prototype.unique = function(){ // found on this forum

    var r = new Array();

    o:for(var i = 0, n = this.length; i < n; i++){

            for(var x = 0, y = r.length; x<y; x++){

                if(r[x]==this[i]) continue o;}

            r[r.length] = this[i];}

        return r;

                }

 

newImportArray = importArray.unique();

 

for(var i = numItems; i <= newImportArray.length; i++){

    uniqueImportArray.push(newImportArray[i]);

    }

 

for(var i = 1; i <= uniqueImportArray.length; i++){

var fileArrayString = uniqueImportArray[i].toString()

//alert(fileArrayString);

var fileSplit = fileArrayString.split(".");

//alert(fileSplit[1]);

if(fileSplit[1] == ("jpg")){

    app.project.importFile(new ImportOptions(File("~/Desktop/TEST/" + uniqueImportArray[i])));

                            }

                        }

                               

for(var i = 1; i <= uniqueImportArray.length; i++){

var fileArrayString = uniqueImportArray[i].toString()

//alert(fileArrayString);

var fileSplit = fileArrayString.split(".");

//alert(fileSplit[1]);

if(fileSplit[1] == ("mov")){

    app.project.importFile(new ImportOptions(File("~/Desktop/TEST/" + uniqueImportArray[i])));

    }

}


Viewing all articles
Browse latest Browse all 2143

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>