• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Move footage to folder

Explorer ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Hi all,     

    I'm new to After Effects Scripting. I have developed a script. In this script which moves images to Images folder and Compositions to Composition folder. When i run the script, only few images moves to images folder and few compositions moves to Composition folder. Others did not moved into folder. Could you please help me to improve this script?

var items = app.project.numItems;

    function getFolder(folderName) {

        var result = [];

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

          if (app.project.item(i).name == folderName[0] && app.project.item(i) instanceof FolderItem){

            result.push(app.project.item(i));

          }

        if (app.project.item(i).name == folderName[1] && app.project.item(i) instanceof FolderItem) {

            result.push(app.project.item(i));

          }

        }

        return result;

      }

    var folderNames = ["Images","Composition"];

      var folders = getFolder(folderNames);

     var searchResult = [];

    function search (para) {

        for(var j = 0;j < para.length; j++)

        for (var i=0; i< folders.length; i++)

        if (folders.name == para) {

            searchResult.push(folders);

        }

    }

    search(folderNames);

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

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

                app.project.item(i).parentFolder = searchResult[0];

            }

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

                app.project.item(i).parentFolder = searchResult[1];

            }

    }

Regards,

Sasikumar

TOPICS
Scripting

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Dec 18, 2018 Dec 18, 2018

Hard to track down the error.

You can adapt from this, it should work:

function getItemByTypeAndName(typeName, name){

    var i, item;

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

        item = app.project.item(i);

        if (item.typeName===typeName && item.name===name) return item;

        };

    return null;

    };

function isImageItem(footage){

    // Might need some better tracking...

    return footage.mainSource instanceof FileSource && footage.mainSource.isStill;

    };

//===========================

...

Votes

Translate

Translate
Advocate ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Hard to track down the error.

You can adapt from this, it should work:

function getItemByTypeAndName(typeName, name){

    var i, item;

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

        item = app.project.item(i);

        if (item.typeName===typeName && item.name===name) return item;

        };

    return null;

    };

function isImageItem(footage){

    // Might need some better tracking...

    return footage.mainSource instanceof FileSource && footage.mainSource.isStill;

    };

//==========================================

var compsFolderName = "Compositions";

var imagesFolderName = "Images";

var compsFolder = null;

var imagesFolder = null;

function cleanProject(){

   

    if (!compsFolder){

        // If compsFolder has been removed since last time, try to see if there is one, else create brand new

        compsFolder = getItemByTypeAndName("Folder", compsFolderName) || app.project.items.addFolder(compsFolderName);

        };

    if (!imagesFolder){

        // Same

        imagesFolder = getItemByTypeAndName("Folder", imagesFolderName) || app.project.items.addFolder(imagesFolderName);

        };

   

    var comps = [];

    var images = [];

   

    var i, item;

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

       

        item = app.project.item(i);

       

        if (item.typeName === "Composition"){

            if (item.parentFolder !== compsFolder){

                comps.push(item);

                };

            }

        else if (item.typeName === "Footage"){

            if (isImageItem(item)){

                if (item.parentFolder !== imagesFolder){

                    images.push(item);

                    };

                };

            };

        };

   

    var n;

    for (n=0; n<comps.length; n++) comps.parentFolder = compsFolder;

    for (n=0; n<images.length; n++) images.parentFolder = imagesFolder;

    };

//==========================================

cleanProject();

Xavier

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 05, 2019 Jan 05, 2019

Copy link to clipboard

Copied

UQg​, a side note here: typeName is different based on AE language, so you cannot rely on it to check if an item is Composition, Folder, Footage or whatever, since it will be different in another AE language ¯\_(ツ)_/¯

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 05, 2019 Jan 05, 2019

Copy link to clipboard

Copied

Tomas Sinkunas​ Thx, about time for me to know.

I dont get the point of localizing this, seriously.... What does it bring ???

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 06, 2019 Jan 06, 2019

Copy link to clipboard

Copied

LATEST

No idea Xavier, but I burnet so bad because of this localisation in my compCode tool.

Anyways, Composition and Folder items would return typeNames in EN and RU localisations respectively:

Composition - Композиция;

Folder - Папка;

Life would have been so much easier if typeName wasn't localised 😕

Now back on topic. To fix the code to work on any language, my approach would be to substitute getItemByTypeAndName() function with this one:

function getItemByInstanceAndName(instanceToMatch, name) {

    var item;

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

        item = app.project.item(i);

        if (item instanceof instanceToMatch && item.name === name) {

            return item;

        }

    }

    return null;

}

and search for the item based on its instance name: getItemByInstanceAndName(CompItem, "composition name")

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines