Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Javascript one-time actions. Run code only once. Is it possible?

  • Javascript one-time actions. Run code only once. Is it possible?

     Timur Solomon updated 4 weeks ago 3 Members · 6 Posts
  • Brian Ure

    May 28, 2022 at 7:26 am

    Hello everyone!

    CONTEXT:

    I’m putting together a series of templates that all reference information from one composition.

    That composition consists of 30 text layers where the editors are supposed to introduce a bunch of titles for that video. Then the templates reference the titles in that composition via expressions.

    I don’t want to do this through essential graphics since more than one template is going to reference the contents of the text comp. So the original contents should change.

    QUESTION:

    Is it possible to run a code somehow that switches the text layers back to the default text? Just like you would do with master properties(pull from original comp), but remember I can’t use essential graphics here.

    I would love to offer this option for when the template is cleaned up to get it ready to be used in a new video.

    The problem is that if I add an expression to the source text then it becomes indefinitely overridden by it and the text can’t be edited anymore. I would like to include an option to just set all text to default(default would be as shown in the attachment) but allow that text to be modified again as you would normally.

    Sort of like: Change text to ‘X’ as a one-time action.

    Instead of: Be ‘X’ forever.

    ————————————

    Do you think this would be possible if not with regular expressions, with scripts? i haven’t messed with scripts yet but maybe this would be my chance to start getting truly advanced with java.

    Thank you so much!

  • Walter Soyka

    May 28, 2022 at 6:19 pm

    I don’t understand how this will be used in production. If you don’t mind re-explaining it, I’d love to try to help.

    For now, I’ll just mention that for a lot of my motion graphic templates, I expose text sources from guide layers via Essential Graphics, then use expressions on the actual visible/rendering layers to set the type. This would allow me, for example, to have a default value that’s only overridden if the editor enters new text. These are not directly editable in Premiere’s Program panel, but they are perfectly accessible through Premiere’s Essential Graphics / Edit tab.

  • Timur Solomon

    May 29, 2022 at 5:34 am

    Hi Brian,
    Do I understand correctly that you want to change the text of all text layers in some composition?

    I’m not sure it’s possible to “reset” parameters through expressions. But through a script, it’s possible.

    app.beginUndoGroup("Set Default Text");

    var comp = app.project.activeItem;

    var defaultText = "Insert Title"; // << Type you text here

    for (var i = comp.numLayers; i > 0; i--) {

    var layer = comp.layer(i);

    if (layer instanceof TextLayer) {

    var textProp = layer.property("Source Text");

    textProp.setValue(defaultText + " " + i);

    };

    };

    app.endUndoGroup();

    If you are using KBar, you can create a button to execute a script. You need to open compositions with text layers and run the script to “reset” them.

    If this is what you need. For convenience, you can make an option without having to open a composition with text to run the script. But this requires the name of the composition to set the conditions

  • Brian Ure

    May 29, 2022 at 11:03 am

    Hey, Walter! Thanks for your interest, man. I’ll try to explain better. But I have to say I almost know the answer is going to be that it’s not possible, haha.

    I have two templates, they display the names of the topics that are being discussed. There are many topics in a single video. We create guides to teach viewers how to play a video game.

    The first template is a ‘screen title’ type of template. It takes most of the screen space and it announces when a topic change happens.

    The second template is meant to kick in right after the first one animates out and it’s a small template that only exists in the top right corner of the screen. it also displays the name of the topic for as long as the topic lasts and it has a timer that reaches 0:00 when the topic ends(and the new topic screen kicks in). It also has an optional bar that displays the name of the next topic. It says: ‘Coming up: Name of the next topic’.

    So what I’m trying to solve is that now the editors have to type every topic title 3 times. And that sucks. So I want to find a way for editors to type all titles once in a separate composition; “Global Title Reference”.

    This composition is never going to make it to the final video. It’s meant to serve as a place where editors go, type all the titles for that video, and then the main templates have scripts that go and fetch the correct titles they’re supposed to display within that composition.

    The reason I can’t use essential graphics with this ‘Global Title Reference’ composition is that these titles are meant to be referenced by 2 separate templates that almost have nothing to do with each other. And the master properties don’t change the original contents of the composition. So that would mean that only one template could fetch the correct titles.

    Instead, the templates reference the actual titles inside of the composition. Everything works fine. The only issue is that after the video is done and the editors clean the templates so they’re ready to be used on another video. I have no way to set the text layers inside ‘Global Title Reference’ back to the default “Insert Title” sourceText value.

    This is not entirely necessary to do but I want to figure out how to do this just to simply grow as a coding animator. I really like visual order and cleanliness as well as code elegance so I would love for this global title reference composition not to be tainted with titles from previous projects.

    I’ve attached other images showing the controls being referenced and one of the expressions I’ve written for the title. It fetches the correct title based on an Id menu that the editor assigns and it works through essential properties. You basically use that menu to tell the template what title number it’s supposed to be. At the end it also has an if/else statement that adds a linebreak in the middle if the text bounding box surpasses a certain width.

    How would you go about this? I hope it’s a fun little challenge! I’m currently trying to learn how to do a simple script that only has one button that does this.

  • Brian Ure

    May 29, 2022 at 1:22 pm

    Hey, Timur! Thank you so much for this code! Yes, this is what I’ve been trying to do all day. I took this chance to start learning scripting, which seems even cooler than expressions. I already learned how to create windows and buttons, I learned how to assign functions to buttons but you’re absolutely right I would love to learn how to reference a specific composition! I seem to be getting the syntax wrong somewhere.

    I’ve tried:

    comp(“Global Topic Reference”);

    app.project.comp(“Global Topic Reference”);

    app.project.compItem(“Global Topic Reference”);

    Nothing seems to work for me! I would love it if you could share this with me! I’ve also been looking for educational content but it feels like there’s not a lot out there about Javascript for scripting.

  • Timur Solomon

    May 29, 2022 at 6:32 pm

    Hi Brian,
    You did everything right, you just didn’t have enough information that the composition needs to be found through a loop.
    The code below references your composition. You can make a button for it for convenience.
    I myself have been studying scripts for about six months. And it’s worth it! I wish you success.

    app.beginUndoGroup("Set Default Text");
    var defaultText = "Insert Title"; // << Type you text here
    for (var c = 1; c <= app.project.numItems; c++) {
    var comp = app.project.item(c);
    if (comp instanceof CompItem && comp.name == "Global Topic Reference") {
    for (var i = comp.numLayers; i > 0; i--) {
    var layer = comp.layer(i);
    if (layer instanceof TextLayer) {
    var textProp = layer.property("Source Text");
    textProp.setValue(defaultText + " " + i);
    };
    };
    };
    };
    app.endUndoGroup();
Viewing 1 - 6 of 6 posts

Log in to reply.

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