Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Fit to Comp Width

  • Posted by Borko Grujic on March 5, 2013 at 10:10 am

    Hi,

    How do I call “Fit to Comp Width” on a layer from a script

    I got all other stuff taken care of, I need a function name, I could not find any references for this.

    Thanks,
    B

    Timur Solomon replied 4 years ago 4 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    March 5, 2013 at 7:16 pm

    Assuming your layer is selected and your comp has focus, this should work:

    app.executeCommand(app.findMenuCommandId(“Fit to Comp Width”));

    Or, you could do it this way:

    var myComp = app.project.activeItem;
    var myLayer = myComp.layer(1);
    var s = (myComp.width*myComp.pixelAspect)/(myLayer.width*myLayer.source.pixelAspect)*100;
    myLayer.property(“Scale”).setValue([s,s]);

    Dan

  • John Gate

    August 17, 2021 at 5:36 pm

    Hi Dan,

    Can you please provide similar code for “Fit to Comp” ?

  • Dan Ebberts

    August 17, 2021 at 7:22 pm

    I guess that would be like this:

    var myComp = app.project.activeItem;

    var myLayer = myComp.layer(1);

    var s = myLayer.property("Scale").value;

    var x = (myComp.width*myComp.pixelAspect)/(myLayer.width*myLayer.source.pixelAspect);

    var y = myComp.height/myLayer.height;

    myLayer.property("Scale").setValue([s[0]*x,s[1]*y]);

    Or an expression like this:

    x = (thisComp.width*thisComp.pixelAspect)/(width*thisLayer.source.pixelAspect);

    y = thisComp.height/height;

    [value[0]*x,value[1]*y]

  • John Gate

    August 18, 2021 at 10:16 am

    Thank you very much, and especially for replying even after so many years to this post

  • Timur Solomon

    May 11, 2022 at 5:09 pm

    Hi Dan,

    Thanks for the expression.

    The question is, is it possible to do the same for text? it doesn’t have a source parameter and the expression doesn’t work

  • Dan Ebberts

    May 11, 2022 at 5:25 pm

    I guess it depends on what you’re after exactly. If you just want to scale the text so that its width matches the comp width, a scale expression like this should work:

    s = (thisComp.width/sourceRectAtTime(time,false).width)*100;

    [s,s]

  • Timur Solomon

    May 12, 2022 at 3:14 pm

    Hi Dan,

    Thank you for your help, it helped.

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