Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions scripting : creating comp

  • Nicholas Joseph

    January 19, 2011 at 8:51 pm

    sweet!! that worked… and this also works:

    var compFolder = app.project.items.addFolder(‘comp’);
    compFolder.items.addFolder(‘comp2’);

    thanks again

  • Nicholas Joseph

    January 20, 2011 at 12:51 pm

    hey there again…ignor that last question…i was able to solve it.

    Thanks for all your help Dan…Im sure I will have tons more questions 🙂 I am starting to understand a bit.

    For all those who are in the same boat as me… Here are some notes that I took. Hopw it helps you get started aswell.

    //Creates a new project
    app.project.close(CloseOptions.DO_NOT_SAVE_CHANGES); //close without saving
    app.newProject();
    var proj = app.project;

    //Create Folders
    var compFolder = app.project.items.addFolder('comp'); //Folder called COMP on root DIR

    //Sets Parent Folders
    var compFolder = app.project.items.addFolder('comp'); //folder1
    var compFolder2= app.project.items.addFolder('comp2');//folder2
    compFolder2.parentFolder = compFolder;//makes folder 2 child of folder1
    or
    var compFolder = app.project.items.addFolder('comp'); //folder1
    compFolder.items.addFolder('comp2');//creates folder2 inside of folder1

    //Import a file
    var myfile = app.project.importFileWithDialog(); //the file is stored in array index 1

    //Makes child a partent of a folder
    myfile[0].parentFolder = compFolder2;

    //Get file Attributes and set them to variables
    var myfileWidth = myfile[0].width;
    var myfileHeight = myfile[0].height;
    var myfileFrameRate = myfile[0].pixelAspect;
    var myfileFrameRate = myfile[0].duration;
    var myfileFrameRate = myfile[0].frameRate;

    //Create comp with attributes of the file
    var myComp = app.project.items.addComp( "Hello Comp1", myfile[0].width, myfile[0].height, myfile

    [0].pixelAspect,myfile[0].duration,myfile[0].frameRate);

    //Create a comp in a folder as a child
    var myComp = compFolder.items.addComp(attributes); //creates comp inside compFolder(comp)
    or
    var myComp = app.project.items.addComp(attributes); //Creates new comp on root directory
    myComp.parentFolder = compFolder; //moves from the root to compFolder

    //Addin footage to comp
    var newObj = myComp.layers.add(myfile[0]);//adds myfile to mycomp

    https://www.mitchallen.com/aftereffects/2006/03/after-effects-scripting-101.html
    https://forums.creativecow.net/thread/227/17300
    https://www.adobe.com/products/aftereffects/pdfs/aftereffectscs3_scripting_guide.pdf

  • Nicholas Joseph

    January 22, 2011 at 4:29 pm

    hi Dan…Im back 🙂

    Can you help me with an issue I am having please…
    I am having trouble accessing info/data from an imported file.

    Check out the image

    So I have these folders and they are all set in variables.
    I then use:

    function Roto()
    {
    rotoFiles = app.project.importFileWithDialog(); //the file is stored in array index 0
    rotoFiles[0].parentFolder = _ROTOFolder;
    }

    to import another AE file with a directory and some comps. (ROTOTEST.AEP)

    What I am trying to do to get the Comps from the rototest.aep folder and place them in the COMP>Precomp>_DM folder. Can you help me with that code please.

    As always…Thank you very much for all your help. I owe you a pint.

    Here is how I created the folders:

    var compFolder;
    var _DMFolder;
    var PreCompFolder;
    var _ELFolder;
    var _MFolder;
    var sourceFolder;
    var _MMFolder;
    var _ROTOFolder;

    function FolderStructure()
    {
    compFolder = app.project.items.addFolder(‘COMP’);
    sourceFolder = app.project.items.addFolder(‘SOURCE’);
    PreCompFolder = compFolder.items.addFolder(‘PRECOMP’);
    _DMFolder = PreCompFolder .items.addFolder(‘_DM’);
    _ELFolder = PreCompFolder .items.addFolder(‘_EL’);
    _MFolder = PreCompFolder .items.addFolder(‘_M’);
    _MMFolder = sourceFolder.items.addFolder(‘_MM’);
    _ROTOFolder = sourceFolder.items.addFolder(‘_ROTO’);
    }

  • Theo Van laar

    January 23, 2011 at 5:40 pm

    What is the best way to learn how to script in AE? I am a MAYA TD but it seems AE is 10 times harder than scripting in Maya. Do you have any resources that you recommend?

    https://www.amazon.com/After-Effects-Expressions-Marcus-Geduld/dp/024080936X

    Theo

  • Dan Ebberts

    January 23, 2011 at 7:18 pm

    I haven’t tested any of this code, but I’d think you need a little routine that tests to see if a comp is in the folder structure that needs to be moved and a loop that checks every comp in the project. Something like this:


    function compTest(theItem);
    if (!(theItem instanceof CompItem)) return false;
    var temp = theItem.parentFolder;
    if (temp == null || temp.name != "M_") return false;
    temp = temp.parentFolder;
    if (temp == null || temp.name != "PreComp") return false;
    temp = temp.parentFolder;
    if (temp == null || temp.name != "COMP") return false;
    temp = temp.parentFolder;
    if (temp == null || temp.name != "ROTOTEST.aep") return false;
    temp = temp.parentFolder;
    if (temp == null || temp.name != "_ROTO") return false;
    temp = temp.parentFolder;
    if (temp == null || temp.name != "SOURCE") return false;
    return true;
    }

    var myItem;
    for (i = 1; i <= app.project.numItems; i++){ myItem = app.project.item(i); if (myItem instanceof CompItem){ if (compTest(myItem)) myItem.parentFolder = _DMFolder; }

    Dan

  • Nicholas Joseph

    January 24, 2011 at 6:01 am

    yooo… thanks.. I wasn’t quite sure what was going on in your example but i was able to understand pieces of it. Because my folders are always the same(same index) i was able to write this and it worked great. 😉

    var RotoMaskFolder = rotoFiles[0].item(1).item(1).item(1);
    var numberItems = RotoMaskFolder.numItems;
    for(var i = numberItems; i >=1; i– )
    {
    //alert(RotoMaskFolder.item(i).name);
    var matte = RotoMaskFolder.item(i).duplicate();
    matte.name = RotoMaskFolder.item(i).name;
    matte.parentFolder = _MFolder;
    }

    Hey… are you the same Dan that owns the motionscript site??
    i always use motionscript.com and nabscripts.com for reference.

    thanks again

  • Nicholas Joseph

    February 2, 2011 at 9:26 pm

    Hi there Dan…Its been a few days..and I’m back. 🙂

    I’m having an issue with finding a length of a string.

    so… here is what I have…

    var mySelection = app.project.selection; (selection of a .mov file with the name “smf_zzh110_v10”) and what I get is a string array with “smf_zzh110_v10” stored in index 0.
    but now…I want to get the lenght of the array of index[0].
    when I use “alert(mySelection[0].length)” i get an error.

    How would I go about removing “zzh110” from the string[0].

    so pretty much how to get the length of an array inside of an array.

    Hope you can help…

    Thanks Again

    Nik

  • Dan Ebberts

    February 2, 2011 at 9:32 pm

    I think your problem is that the selection array is an array items, not strings. To get the name, you need to do something like this:

    var mySelection = app.project.selection;
    var myStr = mySelection[0].name;

    Dan

  • Nicholas Joseph

    February 2, 2011 at 10:30 pm

    yesss.. that worked beautifully.

    Thanks Again for all your help.

  • Nicholas Joseph

    February 22, 2011 at 12:42 am

    Hi there Dan…Its been awhile 🙂

    Can you please help me with another issue I am having…

    I am trying to replace a footage with the same footage(updated) but in a different folder.
    Here is my test::

    var myFile = app.project.selection;
    var myFileName = myFile[0].name;
    var indexOfFile = myFileName.indexOf(“.”);
    var myFileFolderName = myFileName.slice(0,indexOfFile);
    var myFileLocation = myFile[0].mainSource.file;

    var selectFolder = Folder.selectDialog(“Select ReTarget Root”);
    var targetFolder = selectFolder.toString();

    targetFolder = targetFolder + “/” + myFileFolderName + “/” + myFileName;

    myFile[0].mainSource.file.missingFootagePath(targetFolder);

    The last line always errors out. Can you please look over my code and tell me where I went wrong.

    Thanks Again,

    NIK

    Thanks Theo…I shall look it up.

Page 2 of 4

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy