AE ENHANCERS

Expressions/Scripts/Presets
It is currently Sat May 25, 2013 12:06 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 63 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject:
PostPosted: Sat Mar 31, 2007 4:25 pm 
Offline

Joined: Tue Nov 29, 2005 3:00 am
Posts: 201
Location: Paris
Hi guys,

actually we don't need any plug-in to retrieve the text layer dimensions, scripting provides all we need. Less than ten lines of scripting are required.

the key is the use of the -undocumented- "executeCommand()" application method.

we can create a new mask (default rectangular mask) around the text and retrieve its dimensions with simple math on mask vertices coords (right-left, top-bottom)

we get the command id by calling the -undocumented- findMenuCommandId(), that takes the name of the command as argument.

here is a example that illustrates this technique:

Code:
{
   app.executeCommand(2367); // 2367 : app.findMenuCommandId("New Mask")
   var myTextLayer = app.project.activeItem.selectedLayers[0];
   var myMask      = myTextLayer.Masks.property(myTextLayer.Masks.numProperties);
   var myVertices  = myMask.maskShape.value.vertices;
   var TextWidth   = Math.abs(myVertices[0][0] - myVertices[3][0]);
   var TextHeight  = Math.abs(myVertices[0][1] - myVertices[1][1]);
   alert("Size of text in pixels:\t\r\r" +
         "   width\t = " + TextWidth.toFixed(3) + "\r" +
         "   height\t = " + TextHeight.toFixed(3));
   myMask.remove();
}


http://www.nabscripts.com/Forum/Scripts/myScripts/textDimensions.jsx


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 31, 2007 4:48 pm 
Offline

Joined: Thu Oct 21, 2004 12:36 am
Posts: 86
Location: Phoenix, AZ
Fascinating. I'll have something to look forward to whenever I get around to upgrading from 6.5.

Am I to presume this works equally well when the text in the layer extends beyond the bounds of the comp?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 8:54 am 
Offline

Joined: Tue Mar 14, 2006 2:16 pm
Posts: 98
Location: Atlanta, GA
Hey nab,

Once again, some nice sleuthing.

Dale

_________________
Dale Bradshaw
Technology Director | Primal Screen
creative-workflow-hacks.com
Atlanta, GA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 8:56 am 
Offline

Joined: Wed Jul 07, 2004 2:30 pm
Posts: 319
Location: Charlotte, NC
How did you find that tidbit Dale?

_________________
Byron Nash
CG/VFX Generalist
http://www.editatjoes.com
http://www.armoredsquirrel.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 9:05 am 
Offline

Joined: Tue Mar 14, 2006 2:16 pm
Posts: 98
Location: Atlanta, GA
Hey Byron,

Chris Prosser from Adobe posted app.executeCommand(app.findMenuCommandId(”Auto-Orient…”)) in reference to an auto-rig script I was having difficulty writing. nab was clever enough to figure out the mask from "New Mask" would be the same dimensions as the text layer.

Dale

_________________
Dale Bradshaw
Technology Director | Primal Screen
creative-workflow-hacks.com
Atlanta, GA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 10:33 am 
Offline

Joined: Wed Jul 07, 2004 2:30 pm
Posts: 319
Location: Charlotte, NC
So, can you just plug in any menu item to that function and it will execute it?

_________________
Byron Nash
CG/VFX Generalist
http://www.editatjoes.com
http://www.armoredsquirrel.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 11:51 am 
Offline

Joined: Tue Mar 14, 2006 2:16 pm
Posts: 98
Location: Atlanta, GA
byronnash wrote:
So, can you just plug in any menu item to that function and it will execute it?


pretty much. If the menu command throws up a GUI dialog the user will still have to deal with that.

Dale

_________________
Dale Bradshaw
Technology Director | Primal Screen
creative-workflow-hacks.com
Atlanta, GA


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 9:39 am 
Offline
Enhancement master
User avatar

Joined: Thu Jun 17, 2004 9:27 am
Posts: 456
Location: New York City, NY
wow.. this is huge! way to go guys!! :D


Top
 Profile  
 
 Post subject: wow!
PostPosted: Thu May 17, 2007 4:41 pm 
Offline

Joined: Tue Jun 21, 2005 2:08 pm
Posts: 9
this is really, REALLY, great. Thanks!

I've been having troubles with the app.executeCommand (esp in the cs3 beta) but I got around that by just leaving a mask there in the source project, and then removing it after i get the size of the text layer.


Top
 Profile  
 
 Post subject: Fit Text to Box
PostPosted: Thu May 17, 2007 7:38 pm 
Offline

Joined: Tue Jun 21, 2005 2:08 pm
Posts: 9
After playing with this for a while, I realized you need to compensate for the anchor point when scaling. Whipped this up - let me know what you guys think:

Code:
function fitTextToBox(myTextLayer,boxX,boxY){

   var myMask;
   var myVertices;
   var thePosition;
   var TextWidth;
   var TextHeight;
   var NewScale;


   myTextLayer.selected=true;
   app.executeCommand(2367); // 2367 : app.findMenuCommandId("New Mask")
   myMask   = myTextLayer.Masks.property(myTextLayer.Masks.numProperties);
   myVertices = myMask.maskShape.value.vertices;
   
   //re-set the anchor point to account for 1st character margin
   //assumes left justification
   if(myVertices[0][0]!=0){
      theAnchorPoint=myTextLayer.property("Anchor Point").value;
      theAnchorPoint[0]=theAnchorPoint[0]+myVertices[0][0];
      theAnchorPoint[1]=theAnchorPoint[1]+myVertices[1][1];
      myTextLayer.property("Anchor Point").setValue(theAnchorPoint);
   }
   
   textX = Math.abs(myVertices[0][0] - myVertices[3][0]);
   textY = Math.abs(myVertices[0][1] - myVertices[1][1]);
   
   newX=(100*boxX)/textX;
   newY=(100*boxY)/textY;

   myTextLayer.property("Scale").setValue([newX,newY]);
   
   myMask.remove();

}


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 20, 2007 2:14 pm 
Offline

Joined: Tue Nov 29, 2005 3:00 am
Posts: 201
Location: Paris
Hi austin,
looks ok to me !

(right-click to open zoom options)
http://www.nabscripts.com/Forum/Scripts/images/TextPacking_test000.swf


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 20, 2007 9:27 pm 
Offline

Joined: Tue Jun 21, 2005 2:08 pm
Posts: 9
wow. killer layout, nab. looks like a lot of fun can be had here :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 28, 2007 9:07 am 
Offline

Joined: Wed Jul 07, 2004 2:30 pm
Posts: 319
Location: Charlotte, NC
I'm having trouble getting this to work on a script that loops through a lot of layers/comps. It seems like the comp that the layer is in needs to be active but there is no way to set the activeItem. How are you guys handling this problem?

_________________
Byron Nash
CG/VFX Generalist
http://www.editatjoes.com
http://www.armoredsquirrel.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 28, 2007 1:28 pm 
Offline

Joined: Tue Nov 29, 2005 3:00 am
Posts: 201
Location: Paris
Yes that's right. You could try to create new text layers in the activeItem based on the text source of layers that are located in other comps to evaluate their size.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 29, 2007 7:33 pm 
Offline

Joined: Wed Jul 07, 2004 2:30 pm
Posts: 319
Location: Charlotte, NC
Wow, that's a tough one, I'm not sure what the activeItem is going to be each time. I guess I'll do some testing and see how it works.

_________________
Byron Nash
CG/VFX Generalist
http://www.editatjoes.com
http://www.armoredsquirrel.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 63 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group