Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Ae project cleanup script, help with Parenting and pre-comps

Community Beginner ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

Hello, I am working on making a customized version of the project cleanup script written by Arttu Rautio. I've modifed it a bit to suit our teams particular workflow but basically the script goes through each project asset and based on the file extension and puts it in the proper folder for its asset type (footage, images, audio etc.) I woud like the script to do a few things that I haven't been able to crack.

 

1) I'd like it to place any pre-comps in the "pre comps" folder, I have tried doing this with a comaparator that looks for comps that have also been used more than once in other comps,  "usedI" property greater than 0, I am not executing this right but I left it in the script. it is one of the last lines.

 

2) I'd also like to skip assets that are already inside of folders or already have parents. So for example we always put our footage into subfolders for Cam A, Cam B, etc. Currently When this script gets run it moves that footage out of the subfolders and into the root footage folder. I really just want this to effect assets that are loose or have yet to be organized int he project root.

 

3) This might go hand in hand with point 2 about skipping parented items, but I'd like to be able to keep assets imported as folders like .aep templates or folders called "layers" that get created when you import a illustrator/photoshop file to stick together in there parent folders as well. Any help on any of these goals would be greatly appreciated thank you: 

 

 

 

 

var items = new Array();
var filename;
var fileformat;
// Supported file formats
var audios = ['.aac','.m4a','.aif','.aiff','.mp3','.wav','.wma','.mpa']; // Audio file formats
var videos = ['.gif','.swf','.flv','.avi','.mpeg','.mov','.mp4','.wmv','.vob','.m4v','.flm','.webm','.f4v','.mpv','.r3d','.mxf']; // Video file formats
var images = ['.ai','.psd','.pdf','.dpx','.cin','.jpg','.jpeg','.pxr','.bmp','.gdr','.png','.tiff','.tif','.tga','.exr','.pct','.pcx','.pbm','.raw','.nef','.cr2','.dng','.raf','.rpf','.rla','.jpe','.crw','.raf','.hdr']; // Image file formats
// Functions
function CleanProject() {
    app.beginUndoGroup("AR_CleanProject"); // Begin undo group called AR_CleanProject
    // Collect all items to an array
    for(var i = 1; i <= app.project.numItems; i++) { items[items.length] = app.project.item(i); 
    { if ((app.project.item(i) instanceof FolderItem) && (app.project.item(i).name == "Images"))
        folder_images = app.project.item(i);}
        
    { if ((app.project.item(i) instanceof FolderItem) && (app.project.item(i).name == "Footage"))
        folder_videos = app.project.item(i);}
        
    { if ((app.project.item(i) instanceof FolderItem) && (app.project.item(i).name == "Audio"))
        folder_audio = app.project.item(i);}

    { if ((app.project.item(i) instanceof FolderItem) && (app.project.item(i).name == "Comps"))
        folder_comps = app.project.item(i);}

    { if ((app.project.item(i) instanceof FolderItem) && (app.project.item(i).name == "Pre-Comps"))
        folder_preComps = app.project.item(i);}
        }
    // Check if there are that kind of items
    for (var j = 0; j < items.length; j++) {
        if (items[j].file) {
            filename = items[j].file.name; // Get file name
            fileformat = filename.substring(filename.lastIndexOf(".")); // Get file format
            fileformat = fileformat.toLowerCase(); // File format to lower case
            for (var k = 0; k < images.length; k++) { if (images[k] === fileformat)  } // Check if there is any image file(s)
            for (var k = 0; k < audios.length; k++) { if (audios[k] === fileformat) } // Check if there is any audio file(s)
            for (var k = 0; k < videos.length; k++) { if (videos[k] === fileformat)  } // Check if there is any video file(s)
        }
    }
    // Sort items to new folders
    for (var j = 0; j < items.length; j++) {
        if (items[j].file) {
            filename = items[j].file.name;
            fileformat = filename.substring(filename.lastIndexOf("."));
            fileformat = fileformat.toLowerCase();
            for (var k = 0; k < audios.length; k++) { if (audios[k] === fileformat) { items[j].parentFolder = folder_audio; } } // If audio format found
            for (var k = 0; k < videos.length; k++) { if (videos[k] === fileformat) { items[j].parentFolder = folder_videos; } } // If video format found
            for (var k = 0; k < images.length; k++) { if (images[k] === fileformat) { items[j].parentFolder = folder_images; } } // If image format found
        }
        if ((items[j].typeName == "Composition") && (items[j].usedIn.length > 1 )) { items[j].parentFolder = folder_comps; } else { items[j].parentFolder = folder_preComps;}
    }
    app.endUndoGroup(); // End undo group
}
CleanProject(); // Run CleanProject function

 

 

TOPICS
Scripting

Views

122

Likes

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

Adobe Community Professional , Apr 10, 2021 Apr 10, 2021
Instead of using app.project.item(), you could itereate over all elements of app.project.rootFolder.items. This will only give you the items that are not inside a subfolder. See https://ae-scripting.docsforadobe.dev/general/project/#project-rootfolder

Likes

Translate

Translate
Adobe Community Professional ,
Apr 10, 2021 Apr 10, 2021

Copy link to clipboard

Copied

Instead of using app.project.item(), you could itereate over all elements of app.project.rootFolder.items.

This will only give you the items that are not inside a subfolder.

See https://ae-scripting.docsforadobe.dev/general/project/#project-rootfolder

 

Likes

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 ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

LATEST

Tahnsk you, This solution helped me to be able to make several modifcations since I was only dealing iwth root folders, I'm wondering if you know a way to only organize the pre-comps? does extendscript give us the ability to see how many times a compw as used, is that what aiItem.usedIn is for?

Likes

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