Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects scripting 101

  • scripting 101

    Posted by Sebastian Moreno on May 16, 2020 at 6:33 pm

    Hi everyone,
    I am trying to get deeper into scripting but I want to improve the noob way i do it until now.
    Question:

    I have defined a variable — var mycomp in a function.
    then I want to use that var mycomp to do more things in a second function.
    Somehow — return mycomp; wont work. Should out it in the parameters of the second function or first? or get that var mycomp in a special way?

    I know this is basic, but I would be grateful to learn this now than later.

    Walter Soyka replied 6 years ago 4 Members · 3 Replies
  • 3 Replies
  • Graham Quince

    May 17, 2020 at 4:58 pm

    Would var localcomp = this.mycomp work?

    Not used this in AE l, but when I code with JavaScript in web pages, each function is ‘closed’ and you need to use this. to view global variables.

    Also return mycomp when send mycomp back to another function outside the current one.

    http://www.YouTube.com/ShiveringCactus – Free FX for amateur films
    https://shiveringcactus.wordpress.com/ – FX blog

  • Tomas Bumbulevičius

    May 18, 2020 at 7:51 am

    Sebastian – where exactly return mycomp doesn’t work? Could you share the following:
    1. How do you call the function 1 in ‘main area’ of your script?
    2. How do you defined retrieved variable from function 1?

    Find out more:
    Motion Graphics Design & After Effects Tutorials
    On YT
    On VH

  • Walter Soyka

    May 19, 2020 at 6:44 pm

    This little snippet shows it in action:

    function createNewComp(newCompName) {
    var newCompItemObject = app.project.items.addComp(newCompName, 1920, 1080, 1, 10, 30);
    return newCompItemObject;
    };

    function addSolidToComp(compObject) {
    var newSolidLayer = compObject.layers.addSolid([0,0,0], "New Solid", compObject.width, compObject.height, compObject.pixelAspect, compObject.duration);
    }

    var newComp = createNewComp("Test Comp 1");
    addSolidToComp(newComp);

    Walter Soyka
    Designer & Mad Scientist at Keen Live [link]
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

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