Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scripting question: Is it possible to execute the “Trim Comp to Work Area” command in a script?

  • Scripting question: Is it possible to execute the “Trim Comp to Work Area” command in a script?

    Posted by Matthew Gadbois on August 8, 2012 at 11:35 pm

    I’m a longtime AE user, but just getting in to scripting. After digging through the AE scripting guide I can’t see a way to perform the convenient “Trim Comp to Work Area” command.

    I could do something like this:
    // get the comp item
    var myComp = app.project.items(1);
    // set the comp's duration to 5 seconds
    myComp.duration = 5;
    // set the work area to start at 1 second
    myComp.workAreaStart = 1;
    // set the work area duration to 3 seconds
    myComp.workAreaDuration = 3;

    If the Work Area started at the beginning of the Composition I could just do this:
    myComp.duration = 3;

    But if I want to trim off the first second of the Comp and then have its duration be 3 seconds, I’m not sure how I can do that. Any help is much appreciated!

    Thanks!
    ~Matt

    Xavier Gomez replied 13 years, 5 months ago 4 Members · 9 Replies
  • 9 Replies
  • Dan Ebberts

    August 9, 2012 at 12:33 am

    If you have CS6, you should be able to give focus to the comp, and then use the menu command like this:

    yourComp.openInViewer();
    app.executeCommand(app.findMenuCommandId(“Trim Comp to Work Area”));

    Dan

  • Matthew Gadbois

    August 9, 2012 at 12:45 am

    Thanks for your reply, Dan. I haven’t upgraded to CS6 yet, are there any solutions you know of that will work with CS4?

    Thanks!
    ~Matt

  • Dan Ebberts

    August 9, 2012 at 1:04 am

    There is a hack for giving focus to a comp. It’s ugly, but it might work for you. It would be like this:

    var durSave = yourComp.workAreaDuration;
    yourComp.workAreaDuration = 0.06;
    yourComp.ramPreviewTest(“”,1,””);
    yourComp.workAreaDuration = durSave;
    app.executeCommand(app.findMenuCommandId(“Trim Comp to Work Area”));

    I haven’t tried it with CS4, but it would be worth a shot.

    Dan

  • Matthew Gadbois

    August 9, 2012 at 1:18 am

    That worked perfectly! Thank you, Dan! I have also learned a ton over the years from your motionscript.com site. I can’t thank you enough sir, you rock!

    Thanks!
    ~Matt

  • Billy Sides

    November 29, 2012 at 1:02 am

    Can this work in an expression or just a script?yourComp.openInViewer();
    app.executeCommand(app.findMenuCommandId("Trim Comp to Work Area"));

    I am setting up a template Comp for creating previews in and would like the Comp to either change to a specified layers length, or set the work area to that layers out point automatically. This usually gets overlooked and the previews end up with blank frames at the end, or the content gets cut short. Only need this if it can work as an expression.

    Also how do you write this correctly? I’ve tried several variations with no luck. thisComp.layer("myComp").Duration; I was trying to change the source text of a text layer as a visual to prompt the user to update the comp length.

    -bsides

    -bsides

  • Dan Ebberts

    November 29, 2012 at 1:24 am

    There’s no way to trim a comp with an expression.

    For your second question, layers don’t have a duration attribute, but this will probably give you what you’re looking for:

    thisComp.layer(“myComp”).outPoint;

    Dan

  • Xavier Gomez

    November 29, 2012 at 11:56 am

    Hello,
    i’ve been trying to ask this question on AE enhancers for few days but registration is quite a long process there so i’ll jump on this bus.

    Is it possible for a script to launch a particular window (i’m thinking of the Smoother window) and run an action within than window (set smooth to, say, 3 and then aplly the smooth to the selected layer) ?

    i’ve tried :

    var smoothPal = Window.find(“palette”, “Smoother”);
    if (smoothPal instanceof Window){smoothPal.center();smoothPal.show();}
    else{smoothPal.layout.layout(true);}

    Unsurprisingly, nothing happens… and even if the smoother palette happened to show itself, i wouldnt know what to do then since i dont know the property/methods used by this palette. The AE scripting guide doesnt say anything about it, so it might not be available to scripting… ?

    Any idea welcome.

    Xavier

  • Xavier Gomez

    November 29, 2012 at 3:14 pm

    OK… i just realised that

    app.executeCommand(app.findMenuCommandId(“Smoother”));

    (or app.executeCommand(5017);)

    does open the Smoother palette.
    But how to pass a tolerance value to that window and simulate an onClick() event on the apply button ?

  • Xavier Gomez

    November 29, 2012 at 3:15 pm

    OK… i just realised that

    app.executeCommand(app.findMenuCommandId(“Smoother”));

    (or app.executeCommand(5017);)

    does open the Smoother palette.
    But how to pass a tolerance value to that window and simulate an onClick() event on the apply button ?

    Xavier

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