Skip navigation
Currently Being Moderated

How to fit text layer to extents of comp with scripting?

Jul 30, 2012 1:19 PM

Tags: #text #rescale #textlayer

Hi There,

 

I'm trying to do something relatively simple, but am having trouble figuring out why it's not working.  I want a script that scales a text layer to the correct size so that it fits the extents of its parent comp.  I have found a couple of resources that do this, but I think these scripts assume that AE is running with its GUI.  In my case, I'm running afterfx.exe from a batch script with the -noui switch.  So, when running AE with the -noui switch, it seems that using the app.executeCommand() function doesn't seem to work right.  Here are the threads I found for handling exactly what I want, but that both incorporate the app.executeCommand() method:

 

http://www.aenhancers.com/viewtopic.php?f=8&t=150&start=45

 

and

 

http://aenhancers.com/viewtopic.php?f=8&t=150&start=60

 

Does anybody have any other suggestions for writing a script that fits a text layer to size, or are these the only alternatives out there?

 

Thank you for your time and help!

 
Replies
  • Currently Being Moderated
    Jul 30, 2012 1:48 PM   in reply to Lazlo Hollyfeld

    You don’t need to use app.executeCommand() for that any more. Something like this should work:

     

    {

      var myComp = app.project.activeItem;

      var myLayer = myComp.layer(1);

      var myRect = myLayer.sourceRectAtTime(0,false);

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

      var myNewScale = [myScale[0]myComp.width/myRect.width,myScale[1]myComp.height/myRect.height];

      myLayer.property("Scale").setValue(myNewScale);

    }

     

    Dan

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 2:17 PM   in reply to Lazlo Hollyfeld

    I think you just need to change one line:

     

    var myNewScale = myScale*Math.min(myComp.width/myRect.width,myComp.height/myRect.heigh t);

     

     

    Dan

     

    Edit:  There's an extra space in the last word and I can't seem to edit it out. You'll figure it out.. :-)

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points