Skip to main content
Legend
April 20, 2013
Question

[Tutorial] After Effects ExtendScript Script Writing

  • April 20, 2013
  • 11 replies
  • 32161 views

Hi all, just wanted to share a new tutorial series I have launched today that I think a lot of you may find helpful.

We've all posted here in this forum looking for help with scripting. There are many reasons why too. One of which that keeps making the rounds is the lack of documentation for ExtendScript. When I first started scripting for After Effects five years ago, the CS3 guide is all there was and it did contain the proper information, but as a newbie I was unable to understand the guide to get any real help from it. I didn't know Javascript then and I was super frustrated. Asking questions and searching forums like this was my only option really. No real training existed, that I'm aware of, that truly covered how to use ExtendScript. That is, until now. I have spent the better part of my weekends over the past year recording this training series to give the After Effects community a decent collection of information in one place to help get people started in scripting. This series comes in at over ten hours in length and is being released in segments on a weekly basis as of today. There is a lot to cover in ExtendScript and I do cover much of it. I'm unable to hit 100% of it as I too am still learning some of the more advanced aspects of it. I do cover however the basics of Javascript, looping through project items, creating folders, creating comps, creating layers, reading various project information, building GUI's, creating/reading txt documents, etc...

If you are a newbie looking to learn ExtendScript, a frustrated artist who's confused by programming, a script developer looking for more info, then at one point or another I believe this series will help you.

The first three episodes begin here:

http://provideocoalition.com/news/video/after-effects-extendscript-training-ep-1-2-3

Keep an eye out for more posts each week. thanks, and I hope you find this resource useful.

-David Torno

11 replies

Tomas B. aka Tom10
Inspiring
July 20, 2016

Hello David,

just came here to thank you a lot for the series. It was a great introduction and I already seeking for new ways to improve the workflow through the scripting. Thanks to your tutorials, it opened my eyes through a different perspective and I felt a need to send you props for this. Thanks!

Legend
July 20, 2016

Thank you Tom10, I appreciate the kind words, and I am happy you've discovered new ways to improve your workflow. The less time spent on the repetitive tasks, the more time you are given to focus on the more important creative and design aspects of a project. I like to think this help can only improve the work being created. At the very least, give you a fighting chance in an industry that keeps shrinking deadlines, and lowering budgets.

P.M.B
Legend
January 21, 2021

Hey.  Sorry to revive this old thread but are your tutorials still a good way to get started with extendscript in AE this many iterations on.  If not can you suggest a good resource for me to get started with the current versions.  You can be honest becasue I just bought the package from Gumroad yesterday for $15.   I know nothing about Java or extendscript so I don't know how much things may have changed.   I do have scripting experience in MEL (Maya) but that's sort of it's own thing/  I have zero experience with Java

 

Thanks

~Gutterfish
Wul Voraz
Inspiring
May 5, 2016

Really cool guide my friend, actually i have like a month learning scripting with you, and now, i can understand javascript and write my own codes. So thank you very much.

Participant
May 4, 2016

Hi David,
First of all thank you for the best tutorials you helped me a lot.

I only have one question is it possible to get your scripts? (that you write in tutorials), because I made way too many mistakes rewriting them and some of them some of them do not work.

Legend
May 5, 2016

You are very welcome. Glad it has been helpful for you. The examples I use in the tutorials are mostly unavailable. I say mostly only because bits of them have been made available in other script releases I've made here and there since that series was recorded. The primary reason I don't normally supply the code already typed up is because I believe that hands on learning is the most effective learning. Yes, mistakes will be made, but that is part of the learning process.

If there are any specific hurdles you are encountering I would be more than happy to help explain a possible solution.

Participant
May 5, 2016

I have a problem with tutorial 17.  When i run the script I get an error in line 53 "TypeError: undefined is not an object"
My script:

var fx, log, proj, curComp, folderLoc, selections, selectionsLength, curSelection, propData, headerName, lName;

fx=new Array();

log=new Array();

proj= app.project;

curComp=proj.activeItem;

folderLoc= Folder.selectDialog ("Select folder to save to.");

if(curComp instanceof CompItem){

    selections= collectSelections(curComp);

    selectionsLength= selections.length;

    for(var s=0; 0<selectionsLength; s++){

        fx.length= 0;

        curSelection= selections;

        propData= propRecurse(curSelection,"",fx);

        if(propData!=null){

            headerName=curSelection.name;

            writeDoc(curSelection.name+"\t"+curSelection.matchName+"\r\r"+propData,headerName,folderLoc);

            }else{

                lName=grabParentLayer(curSelection);

                if(lName==null){

                    lName=curSelection.name;

                    }

                log[log.length]=lName+"_"+curSelection.name+"_"+curSelection.propertyIndex;

            }

        }

    if(log.length>0){

        alert ("The fallowing selections had no sub properties.\r\rLegend:\"Layer_PropName_Index\"\r\r"+log.toString().replace(new RegExp(",","g"),"\r"));

    }

writeLn("Process complete.");

}

function collectSelections(compInput){

    try{

        var myCollection, myLayers, myLayersLength, myProperties, myPropertiesLength, curProp, curLayer;

        myCollection=new Array ();

        myLayers =compInput.selectedLayers;

        myLayersLength=myLayers.length;

        myProperties=compInput.selectedProperties;

        myPropertiesLength=myProperties.length;

        for(var p=0;p<myPropertiesLength;p++){

            curProp=myProperties

;

            myCollection.push(curProp);

            }

        for(var l=0;l<myLayersLength;l++){

            curLayer=myLayers;

            if(curLayer.selectedProperties==0){

                myCollection.push(curLayer);

                }

            }

        return myCollection;

        }catch(err){alert(err.line.toString()+"\r"+err.toString());}

}

function propRecurse(a, indent, fx){

    try{

        var propLength = a.numProperties;

        for(var l=1;l<propLength;l++){

            fx.push(indent +"("+ a.property(l).propertyIndex +")"+a.property(l).name+"\t"+a.property(l).matchName);

            if(a.property(l).numProperties>0){

                propRecurse(a.property(l), indent+ "\t", fx);

                }

            }

        if(fx.length>0){

            var j=fx.join("--");

            var r= j.replace(new RegExp("--","g"),"\r");

            return r;

            }else{

                return null;

                }

        }catch(err){alert(err.line.toString()+"\r"+err.toString());}

}

function writeDoc(contents,fileName,folderLocation){

    try{

        var slash, finalName,doc,inc,fileSuffix;

        fileSuffix="_PropData.txt";

        slash=(osCheck()=="PC")? "\\":"/";

        if(folderLocation==null){

            folderLocation="~"+slash+"Desktop";

            }

        finalName=fileName+fileSuffix;

        doc=new File(folderLocation.toString()+slash+finalName);

        if(!doc.exists){

            doc.open("w");

            doc.write(contents);

            doc.close();

            }else{

                inc= suffixInc(fileName);

                writeDoc(contents,inc,folderLocation);

                }

            if(doc.exists){

                writeLn("File saved");

                }

           

        }catch(err){alert(err.line.toString()+"\r"+err.toString());}

}

function grabParentLayer(prop){

    try{

        var result=null;

        if(prop!=null){

            if(prop.toString().indexOf("Layer")!=(-1)){

                result=prop.name;

                }else{

                    grabParentLayer(prop.parentProperty);

                    }

                return result;

            }else{

                 return result;

                }

        }catch(err){alert(err.line.toString()+"\r"+err.toString());}

}

function suffixInc(oldName){

    try{

        var old=oldName.split("_");

        var oldLength=old.length;

        var tail=old[old.length-1];

        var newName;

        if(oldLength>1&&isNaN(tail)==false){

            for(var i=1; i<999;i++){

                if(i>tail){

                    old.splce(old.length-1);

                    newName=old.join("_").toString()+"_"+i.toString();

                    break;

                    }

                }

            }else{

                return oldName+"_1";

                }

            return newName;

        }catch(err){alert(err.line.toString()+"\r"+err.toString());}

}

function osCheck (){

    var userOS=null;

    var win=$.os.indexOf("Windows");

    win !=(-1)? userOS="PC": userOS="MAC";

    return userOS;

    }

Participant
August 25, 2015

Great tutorial series David! Got my first dockable script up and running with a fancy icon button as icing on the cake.

Legend
August 27, 2015

Hahaha, congrats to you, and thanks for the kind words.

Participant
April 7, 2016

For many years know, I wait for some software company to come out with an alternative to AE. I would quit using Adobe products instantly. Sometime, I find generous, dedicated people like you, that make me think that the real value of Adobe are it's user. I'm convinced your efforts, have or will be rewarded in some way.

Thanks a lot for all these great tutorials.

Known Participant
December 13, 2014

Hi Dave,

I know you posted a while ago but I have really enjoyed your tutorial series.

I am currently trying to make my own script and am running into some walls.

I want to generate an AE comp based on a drop down menu and check boxes.

Right now I know how to create the GUI panel as well as have buttons execute functions .onclick but not involve any true false style statements.

I want to be able to choose a template from a dropdown menu for a comp and then have "horizontal" and "vertical" check mark boxes and then a "generate" button. So basically if both checkboxes are ticked it, on click it would generate a 1280 x 720 comp and a 720 x 1280 comp.

Would love some help if at all possible.

Much appreciated and thanks again for the great tutorial series!!!!

Legend
February 24, 2015

Ben,

I want to be able to choose a template from a dropdown menu for a comp

This would be an onChange for the Dropdown. Also you could create the template simply by selecting the option in your dropdown, instead of adding additional checkboxes. Not fully understanding your layout or setup, but you could use this for example...

myDropdown.onChange = function(){

     switch(myDropdown.selection.text){

          case Template1:

               //Code to create Template1

               break;

          case Template2:

               //Code to create Template2

               break;

          case Template3:

               //Code to create Template3

               break;

          default:

               //Do nothing

               break;

     }

}

Legend
July 7, 2013

Episode 14 Just went live.

Episode 1:    (Intro)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-1-2-3

 

Episode 2:    (Javascript Basics p1)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-1-2-3/P2

Episode 3:    (Javascript Basics p2)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-1-2-3/P3

Episode 4:    (After Effects Object Model structure overview / Script Preparation and development tips / Single Item Access of various project items, comps and layers)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-4

Episode 5:    (Access Renderqueue items, output modules and file paths / Multiple item access of project items, comps and layers / Batch change all renderqueue items file paths)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-5

Episode 6:    (Collecting data into an Array() / Changing values / Various tips)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-6

Episode 7:    (Create new comps and folders / Create Null, Solid, and Text layers)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-7

Episode 8:    (Create multiple comps of various sizes / Use Undo group / Add solids to match each comp / Various tips)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-8

Episode 9:    (Globally change blue solids to red / Replace solid name blue with red)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-9

Episode 10:    (Build a custom function to collect all CompItem objects / Modify function to dynamically allow for choice of CompItem, FolderItem or FootageItem)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-10

Episode 11:    (Build a floating GUI with groups, buttons, checkboxes, radio buttons, dropdown lists, progress bars, icon buttons, images, static text, edit text boxes, sliders, scroll bars, panels with names, tabbed panels with multiple tabs, listbox lists, listbox lists with multiple columns, or tree view lists)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-11

Episode 12 Part 1 & 2:    (Build a dockable & floating combo GUI with groups, buttons, checkboxes, radio buttons, dropdown lists, progress bars, icon buttons, images, static text, edit text boxes, sliders, scroll bars, panels with names, tabbed panels with multiple tabs, listbox lists, listbox lists with multiple columns, or tree view lists)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-12

Episode 13:    (ExtendScript Developer Utility script release / Retrieve a list of all project item footage file paths)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-13

Episode 14:    (Processing text strings)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-14

Legend
July 13, 2013
Legend
September 18, 2013

Hey David,

One more question...

If I wanted to add say a listItem to a ListBox from another function in my code, what would be the best way to set that up? How would I get access to "myPanel" from outside the function it is created in?

All the nested functions are getting me confused.

Thanks!

Ben


I know you directed the question to David, but thought I'd share with you how I've done it. 

I have done it two ways, and it is a matter of style.  You can create a global variable, and when you create your "myPanel" just set that global variable to that panel, and you'll be able to access on the control objects via that global variable.  I've also passed around the "myPanel" object from one function to another.  So if you want to access the "myPanel" object locally in a function, use a parameter in your function declaration and when you call the function, just pass the "myPanel" object.

Hope that helps!

Known Participant
June 25, 2013

hi David just wanna thank you for this video tutorials they are just  great But I would like to know how you changed the background color of the document I tried to do the same in the preferences but it only changes the main window and not the current document it keeps with a white background color or maybe it is only available in Mac cause I use a windows based machine.

Once again thank you for great effort you are pputting those video tutorials  

Legend
June 25, 2013

Thank you for the kind words Edgar. As far as the background color, I personally didn't code or alter that, it was it's native color. I was using AE CS6 on Mac OS X 10.7.2. Now there also are going to be variances between AE versions as too how the UI looks. Adobe has been changing things each time to better match the script ui look to the current AE application look. So things like grey window panel, square looking buttons, etc... are happening behind the scenes. With that said, there is an option to change background color for Groups, Panels,  via the ScriptUI Graphics object. Jeff Almasol came up with a solution way back when that I still use from time to time. Here is a quick sample of coloring a palette window and a group within that window.

var win = new Window("palette", "New", undefined);     //Creates window

     var grp = win.add("group");

     var but = grp.add("button", undefined, "TEST");

var winGfx = win.graphics;

var black = winGfx.newPen(winGfx.BrushType.SOLID_COLOR, [0,0,0], 1);

var blue = winGfx.newBrush(winGfx.BrushType.SOLID_COLOR, [0,.75,1], 1);

var green = winGfx.newBrush(winGfx.BrushType.SOLID_COLOR, [0,1,0], 1);

var red = winGfx.newBrush(winGfx.BrushType.SOLID_COLOR, [1,0,0], 1);

var yellow = winGfx.newBrush(winGfx.BrushType.SOLID_COLOR, [1,1,0], 1);

grp.graphics.backgroundColor = green;     //Set group color

win.graphics.backgroundColor = red;     //Set window color

win.center();

win.show();

Known Participant
June 25, 2013

Hey man thanks for giving  me those tips But I realized that my question was not properly made I meant the ESTK´s document background color yours have a grayish color mine is totallly white even after I change it in the ESTK preferences. Maybe that´s how it is in the windows side

only the main window change color not the document´s

Sorry for my poor English   

Legend
June 9, 2013

Episode 10 just went up. I also included the other links here with descriptors so you know what each episode subject focus was.

Episodes 1, 2, & 3:          (Intro / Javascript Basics p1 / Javascript Basics p2)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-1-2-3

Episode 4:          (After Effects Object Model structure overview / Script Preparation and development tips / Single Item Access of various project items, comps and layers)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-4

Episode 5:          (Access Renderqueue items, output modules and file paths / Multiple item access of project items, comps and layers / Batch change all renderqueue items file paths)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-5

Episode 6:          (Collecting data into an Array() / Changing values / Various tips)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-6

Episode 7:          (Create new comps and folders / Create Null, Solid, and Text layers)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-7

Episode 8:          (Create multiple comps of various sizes / Use Undo group / Add solids to match each comp / Various tips)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-8

Episode 9:          (Globally change blue solids to red / Replace solid name blue with red)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-9

Episode 10:          (Build a custom function to collect all CompItem objects / Modify function to dynamically allow for choice of CompItem, FolderItem or FootageItem)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-10

Episode 11:          (Build a GUI with groups, buttons, checkboxes, radio buttons, dropdown lists, progress bars, icon buttons, images, static text, edit text boxes, sliders, scroll bars, panels with names, tabbed panels with multiple tabs, listbox lists, listbox lists with multiple columns, or tree view lists)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-11

Episode 12:          (Build a GUI with groups, buttons, checkboxes, radio buttons, dropdown lists, progress bars, icon buttons, images, static text, edit text boxes, sliders, scroll bars, panels with names, tabbed panels with multiple tabs, listbox lists, listbox lists with multiple columns, or tree view lists)

http://provideocoalition.com/pvcexclusive/video/after-effects-extendscript-training-ep-12

Legend
June 23, 2013

Episode 12 went live just a moment ago.

Note to all After Effects CC users, Adobe has changed the ScriptUI for ExtendScript and the code explained in both episode 11 and 12 of my series may not work properly for you. I am trying my best to find out the newly updated info on the ScriptUI and will try to update the tutorials as soon as I can for CC.

If anyone comes across info related to the ScriptUI CC update, I would love to know. thanks.

Todd_Kopriva
Inspiring
June 23, 2013

> If anyone comes across info related to the ScriptUI CC update, I would love to know.

We're working on a post with that information now. It should be up later this week.

Legend
May 4, 2013
Participant
May 5, 2013

These guides have come at just the right time for me as I too was struggling to understand how ExtendScript was working and how to make the best use of the scripting pdfs.

Looking foward to the rest of your series of videos and hopefully I will be able to automate an idea I have had for sometime with my new understandings of writing scripts.

Thank you for creating these!

Regards

Chris Forrester

Legend
May 6, 2013

You are very welcome Chris. I'm glad to hear from someone that this series is aim at, respond so possitively about it. There are plenty more posts coming, you haven't even reached the half point of the series yet. Thanks for the feedback too, it makes creating these tutorials worth while when hearing from the viewers.

Todd_Kopriva
Inspiring
April 21, 2013

Excellent. I eagerly anticipate the rest of the series.

Legend
April 21, 2013

Thanks Todd, with all of our scripting guide communication over the years and the long wait for the CS6 guide, it has always been a passion project of mine to put together a video series on this subject to help people who are in the same boat as I was so many years ago. :) Took me awhile, but here I am and while this is no replacement for the hard work you and Jeff Almasol have put into making the pdf guides, it hopefully will be a nice companion to to smooth over the learning curve of understanding ExtendScript and the CS6 guide for non programming artists like myself. Thank god I have a tech oriented mind, lol. If you are able to help spread the word, please feel free to do so. ;) Thanks for all your help over the years too, it's very much appreciated. Many beers are owed to you. ;)

Todd_Kopriva
Inspiring
April 21, 2013

> If you are able to help spread the word, please feel free to do so.

You can count on that.