Skip to main content
Participant
September 19, 2014
Question

Move footage item to folder problem.

  • September 19, 2014
  • 0 replies
  • 977 views

Hi,

I have a problem. I have created script with following action:

  1. Import footage.
  2. Create "_MAIN_RENDER_FX##" comp from footage.
  3. Precomp footage from _MAIN_RENDER_FX## to _MAIN_COMP_FX##.
  4. Add it to render queue.
  5. Create "Composition" and "Footage" folder.
  6. Add comp to Composition folder and footages to Footage folder.

Problem is that if I move Footages to "Footages" folder in the script and launch script again to import another footage,

It will keep in memory older footage information. If I comment that section out which moves footages to "Footages" folder it works,

It even works if I move footage to folder by hand and run script again.

My script consists three functions:

  1. getInfoItem(item) // takes footage item and parse filename to different keywords.
  2. findFolderItemByName(name) // this just checks that if folder exists by given name.
  3. ChooseFile() // This is where we do import stuff which i explained earlier.

Can you spot mistake from my code or give some advice to improve my coding (Im quite new of scripting)?

NOTE: This is hard coded to our project folder structure so getInfoItem function only works with this kind of folder structure.

Windows: X:\Projects\<Project>\Exports\VFX\FX##\

MAC: /Volumes/<NetworkDrive>/Projects/<Project>/Exports/VFX/FX##/

function getInfoItem(item){

  

    // Test OS

    var OS = $.os;

  

    if (OS.search("Windows") != -1) {

        OS = "Windows";

        var splitNum = 4;

    } else {

        OS = "Mac";

        var splitNum = 5;

    }

  

    //  KEYWORDs

  

    this.fullpath = item.file;

    this.fullpath = String(this.fullpath);

    this.path_array = this.fullpath.split("/");

  

    this.fxnum = this.path_array[this.path_array.length-2];

     // split path based on splitNum variable which is based which OS currently in use.

    this.project_array= this.fullpath.split("/",splitNum);

    this.project_path = this.project_array.join("/");

    // Make a COPY from this.path_array

    this.path = this.path_array.slice();

    // remove last cell (Filename)

    this.path.pop();

    this.path = this.path.join("/");

    this.path = this.path + "/";

  

  

    this.fps = item.frameRate;

    this.duration = item.duration;

    this.width = item.width;

    this.height = item.height;

    this.name = item.name;

    this.left_index = this.name.indexOf("[");

    this.right_index = this.name.indexOf("]");

    this.sub = this.name.substring(this.left_index+1,this.right_index);

    this.filename = this.name.substring(0,this.left_index-1);

    this.splitted = this.sub.split("-");

    this.first_frame = this.splitted[0];

    this.last_frame = this.splitted[1];

    this.ext = ".dpx"

  

    // FOLDER RULES

    var padding = "#########################";

    this.aeProjectFolder = "/Project_Files/AE/";

    this.renderFolder = "/Renders/VFX/"+this.fxnum+"/";

  

    this.padnum = String(this.first_frame).length;

    this.outputseq = this.project_path+this.renderFolder+this.filename+"_["+padding.slice(-this.padnum)+"]"+this.ext;

    var outputfile = this.outputseq.slice(0,-this.padnum-6);

    this.outputfile = outputfile + this.first_frame + this.ext;

  

    }

function findFolderItemByName(name){

        var found = false;

        for (i = 1; i <= app.project.numItems; i++){

            if (app.project.item(i).name == name && app.project.item(i) instanceof FolderItem ){

                var myFolder = app.project.item(i);

                found = myFolder;

                break

                }

            }

        return found;

}

function ChooseFile(){

    var myItem = app.project.importFileWithDialog();

  

    var checkFile = 1;

    var footage = new getInfoItem(myItem[0]);

    var rndFolder = footage.project_path+footage.renderFolder;

  

    // Create MAIN RENDER Comp

    var comp = app.project.items.addComp("_MAIN_RENDER_"+footage.fxnum,footage.width,footage.height,1,footage.duration,footage.fps);

    // Check if comp or footage folder exists. otherwise create it.

    if(!findFolderItemByName("Compositions")){

        var compFolder = app.project.items.addFolder("Compositions");

        }

    else{

        var compFolder = findFolderItemByName("Compositions");

        }

    if(!findFolderItemByName("Footages")){

        var footageFolder = app.project.items.addFolder("Footages");

        }

    else{

        var footageFolder = findFolderItemByName("Footages");

        }

      

    // Add footage to _MAIN_RENDER_FX## Comp. 

    comp.displayStartTime = footage.first_frame/footage.fps;

    comp.layers.add(myItem[0]);

 

    // Precomp layer from _MAIN_RENDER_FX##

    var layerIndices= [1];

    var precomp = comp.layers.precompose([1],"MAIN_COMP_"+footage.fxnum);

    precomp.parentFolder = compFolder;

    // add Comp to render Queue

    rqi = app.project.renderQueue.items.add(comp);

       

    // Find DPX template and apply

    for (x in rqi.outputModules[1].templates) {

        if (rqi.outputModules[1].templates == "DPX" ){

            rqi.outputModules[1].applyTemplate(rqi.outputModules[1].templates);

            rqi.outputModules[1].file = File (footage.outputseq);        

            }

        }                  

    // Put all footage items to footage folder

    for (i = 1; i <= app.project.numItems; i++){

            if (app.project.item(i).typeName == "Footage"){

                    app.project.item(i).parentFolder = footageFolder;

                }

        }

      

}

ChooseFile();

Thanks,

.M

This topic has been closed for replies.