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

import folder into After Effects CC by using ExtendScript

Community Beginner ,
Nov 21, 2019 Nov 21, 2019

Copy link to clipboard

Copied

Hi, I am trying to create a function to import folder by using Adobe Extendscript into AE CC2018. The function should be same as AE import folder function. Please see attachment below.

 

importFolder_001.PNG

 

 

 

Attachment below is result in AE after  "Import Folder" button is pressed.

 

 importFolder_002.PNG

 

I try to using import file method to import folder, but with no luck. 

app.project.importFile(new ImportOptions(new Folder("C:\\Users\\Username\\Desktop\\type\\line")));

After Effects error: File can not be opened is show out.

 

Hopefully any AE master can help me solve my problem. Thank you very mucher!

 

TOPICS
How to , Import and export , Scripting

Views

3.0K

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
Mentor ,
Nov 22, 2019 Nov 22, 2019

Copy link to clipboard

Copied

From the docs (http://docs.aenhancers.com/general/project/#project-importfile), you can import with dialog. This should be the one from your first screenshot.

 

To get the same functionality without dialog, I think you have to import file by file. In other words: cycling through every file in a given folder with a for- or while-loop.

 

But maybe there is another way - let's wait what the scripting guys say.

 

*Martin

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
Community Beginner ,
Nov 24, 2019 Nov 24, 2019

Copy link to clipboard

Copied

Hi @martinr84659894, very thanks for your reply!

 

Ya, I currently writing a similar script. Get folder name by looping through entire folder and create folder in AE. At the end import file to specific folder.

 

I will post my script in here after done

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
Contributor ,
Nov 23, 2019 Nov 23, 2019

Copy link to clipboard

Copied

I believe this should do what you need!

 

 

var folder = new Folder;
folder = folder.selectDlg("Please select a folder");

if(folder.exists) {
    var files = folder.getFiles();
    importFiles(files, folder.name.replace(/%20/g, " "));
}

function importFiles(files, folderName) {
    app.beginSuppressDialogs();
    // additionally you can create the folder in AE to put all your imported files into
    var folder = app.project.items.addFolder(folderName);
    var imported;
        for(var i = 0; i < files.length; i++) {
            // only import it if its not a folder
            if(files[i].name.indexOf(".") != -1) {
            imported = app.project.importFile(new ImportOptions(files[i]));
            imported.parentFolder = folder;
            }
            }
    app.endSuppressDialogs(false);
    }

 

This particular script avoids folders, and doing a deep search to recreate ANY given folder hierarchy would require a bit more.

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
Community Beginner ,
Nov 24, 2019 Nov 24, 2019

Copy link to clipboard

Copied

Hi Nathan_Lovell_52,

 

Thanks for your reply, I already tried your script. The script is working if multiple subfolders exists.

 

Let say my folder is "~/type/line/images/####.exr". If I choose "type" folder, the script will only import a blank folder without next subfolder.

 

nothing inside "type" foldernothing inside "type" folder

 

The script is worked if without subfolder. Example: "~/type/####.exr"

Worked when "type" folder have image filesWorked when "type" folder have image files

 

Thanks!

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
Contributor ,
Nov 24, 2019 Nov 24, 2019

Copy link to clipboard

Copied

Yes, as mentioned it's going to be a bit more complicated to do n number of folders. You will need to assume each file can be a file or folder, in which case you can add an else statement to the current for loop. Inside the else would be for folder cases, where you could then create another folder using:

 

app.project.items.addFolder(folderName);

 

and then parent it to the previously created folder with

 

folder.parentFolder = folderObject;

Then with your new subfolder, you can use recusion to check if that subfolder has any more files, and continue until you've done a deep re-creation of all the folders.  

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
New Here ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

LATEST

Certainly! Here's a professional answer in points on how to import a folder into After Effects CC using ExtendScript:

  1. Navigate to the Project Panel:

    • In your ExtendScript code, use the app.project.rootFolder property to access the root folder of the After Effects project.
  2. Specify the Folder Path:

    • Set the folder path of the directory you want to import using the Folder object in ExtendScript. For example, var folderPath = new Folder("C:/Path/To/Your/Folder");.
  3. Check if Folder Exists:

    • Ensure the folder exists by using the exists property of the Folder object. If it doesn't exist, handle the error appropriately.
  4. Import Folder Content:

    • Utilize the importFile() or importFileWithDialog() method in ExtendScript to import files from the specified folder. Loop through the files in the folder and use the File object to create footage items in After Effects.
  5. Organize Imported Items:

    • Optionally, you can organize the imported items in After Effects by creating and utilizing folders within the project. This can be achieved using the app.project.rootFolder.items.addFolder(Canuckle Today method.
  6. Display Success Message:

    • After successfully importing the folder content of , display a message or log to confirm the completion of the task. For instance, $.writeln("Canuckle Today Words successfully imported into After Effects.");.
  7. Handle Errors Gracefully:

    • Implement error handling mechanisms to gracefully manage issues such as non-existent folders, file format mismatches, or any other potential problems during the import process.
  8. Close the ExtendScript Script:

    • End your ExtendScript by releasing any resources and closing the script in a clean manner. This ensures the script execution doesn't have lingering effects.
  9. Documentation and Comments:

    • Document your code with comments to explain its purpose and any critical steps. This aids in understanding and maintaining the script in the future.
  10. Testing:

    • Before finalizing the script, thoroughly test it with various folder structures to ensure robustness and compatibility with different scenarios.

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