Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using setActive()

  • Posted by Mitch Mann on March 6, 2013 at 8:15 pm

    I’m trying to have a script put focus on the composition window (to make sure its the “activeItem”).

    It looks like setActive() should do this, but can’t figure out the syntax.
    None of these work:

    app.viewer.setActive(ViewerType.VIEWER_COMPOSITION);
    ViewerType.VIEWER_COMPOSITION.setActive()
    app.activeViewer = ViewerType.VIEWER_COMPOSITION.setActive()
    app.activeViewer.setActive() = ViewerType.VIEWER_COMPOSITION

    Any thoughts?
    MM

    Hani Tiby replied 3 years, 11 months ago 4 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    March 6, 2013 at 9:35 pm

    How about this:

    yourComp.openInViewer();

    Dan

  • Mitch Mann

    March 6, 2013 at 9:48 pm

    The comp name is unknown in my scenario. I just need to activate the viewer window. (If the project window is active, then there isn’t an “activeItem” for my script to act on.)

  • Dan Ebberts

    March 6, 2013 at 10:32 pm

    I can’t see a way to access existing viewers (other than the active viewer) unless they were opened by the script. I think there would need to be a viewer collection object (app.viewers) with attributes like app.numViewers. If the viewer was opened by the script, you should be able to save it and activate it later:

    var yourCompViewer = yourComp.openInViewer();
    .
    .
    .
    yourCompViewer.setActive();

    If you figure out a way to access existing viewers, please post how you did it.

    Dan

  • Mitch Mann

    March 7, 2013 at 1:52 am

    Hey Dan, I think I found a round-about way of doing it.

    If my AE javascript executes an Apple Script that strikes the key ‘backslash’, then that keyboard shortcut toggles between comp window and timeline window. So it makes the comp in the viewer the activeItem. This would solve the problem of having the Project window selected, which results in a null activeItem.

    But I’m switching back to PC soon, so I won’t bother to implement that as an Apple Script. (Anybody know if there’s something similar for Windows?

    The other thing I tried was to execute an AE menu command to do it. Like this:

    app.executeCommand(app.findMenuCommandId(“Composition: Comp 1”));

    But unfortunately the menu command name changes with the comp that’s in the viewer. So here again, it doesn’t work with an unknown comp name.

    Seems like it should be easy, but its not!
    (-:

    Cheers,
    Mitch

  • Dan Ebberts

    March 7, 2013 at 2:13 am

    Interesting. I don’t know if this helps, but you can use findMenuCommandId to get the id number of the command. For example, on my system

    alert (app.findMenuCommandId(“Timeline: Comp 1”));

    gives -524316

    then I can do this:

    app.executeCommand(-524316);

    to give focus to the Comp 1 timeline.

    Dan

  • Mitch Mann

    March 7, 2013 at 1:50 pm

    Got it working! And the solution is not setActive().

    One thing to note is that you have to call the command twice, because the first time it closes the comp window, the second time it turns it on and puts focus on it.

    So, to summarize this issue for anyone reading:

    PROBLEM: I have a script running in a ScriptUI panel that acts on layers in the activeItem. But if the user has the project panel selected (instead of timeline or composition), then there is no activeItem, its null. The script doesn’t know what to act on, and fails.

    SOLUTION: Script tests for activeItem, if there isn’t one, then running this command twice will select the comp window and make it the activeItem:
    app.executeCommand(-524309);
    app.executeCommand(-524309);

    I’m not sure how those numbers work, but I got them using Dan’s suggestion of this:
    alert (app.findMenuCommandId(“Composition: Comp 1”));

    You need to use those numbers, because the “Comp 1” will change depending on what comp is open, so you can’t call the menu command by name. I’ve tested using the command number with different comp names and it works.

    Selecting the timeline instead of the composition would work too. But be careful, if you have multiple timelines open, it won’t work. It’ll just close two of the timelines. In my workflow I have multiple timelines open for multiple comps, but I only have one comp window open (which of course changes depending on which timeline you have selected.) I suspect that if you had multiple composition windows open, then this solution would probably not work.

    Note that this has further implications that are cool. If you can shift focus to a different window, then you can run an AppleScript (from your Javascript) to hit shortcut keys and do things in that panel that you otherwise couldn’t do with scripting. Like hitting “T” to reveal opacity of selected layer.

    And that’s what I have to say about that, cheers.
    Mitch

  • Jc Ludlow

    June 21, 2013 at 7:11 am

    Code that works for me is
    app.activeViewer.setActive();

  • Hani Tiby

    May 25, 2022 at 5:51 pm

    Thanks Dan, You always rock, openInViewer() worked for me on CC2021

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