Jump to content

Getting size or position of text


Cloaks

Recommended Posts

Hi there Odforce!

I had a small question which I hope someone will know the answer to!

When i'm in the COP context, and I create a text node, how can I then get the actual width of the text? 
As you can see in the top part of the image, there is quite a lot of black padding around the word "Layer". When I drag the text outside of the actual canvas, you can see the blue rectangle that represents the actual size of the word. 

Is there any way I can query the size of that blue rectangle?

Some more background on what I'm trying to achieve:

I would like to move and resize the text to a specific location within a canvas. The text however, isn't predefined, so I would need to know the actual size and position of the text without manually having to override the size to minimize the background behind the letters.

Thank you all for your time!
 

text03.jpg

Link to comment
Share on other sites

I noticed that when I create a Font node in COPs it is populated with $I variable for the integer frame value. On a whim I typed $W and it gave me the comp width. $H gives the comp height. You can also fetch the values of the font scaling using `ch("scale1")`. This is the number you would multiply by the $W to get the width.

	`$W * ch("scale1")`

Link to comment
Share on other sites

Hello Atom, thank you for your reply.

The width and height of the entire font node area isn't exactly what I'm trying to get here though. 

I've added a few images to hopefully better explain the exact details of what I'm trying to get.

Image 01: Roughly measuring the width I get from $W * ch("scale1")
Image 02: Roughly measuring the width I would like to get
Image 03: The blue rectangle in Houdini indicates that it knows those values.

Now the big question is, how to get those values :P

03.jpg

02.jpg

01.jpg

Link to comment
Share on other sites

Entering the following into the text field of the font node yields 0 (zero).

`bbox("../font4", D_XSIZE)`

But that might have been expected due to the documentation for bbox reading as follows; 

Returns bounding box information for a surface node.


I also looked into the python documentation for boundingbox stuff. That gave me hou.BoundingBox() , which instantiates a bounding box. The docs here also mention that it's for geometry. I guess that doesn't include the nodes in a COP2NET :P

Link to comment
Share on other sites

It's:

imgbounds( <coppath>, <planename>, <dimension>, <frame>)

So you'd do something like

imgbounds("/img/cop2net1/font1", "C", "w", $I)

Other dimension names are:

  • x, x1: leftmost bounds
  • y, y1: bottommost bounds
  • x2: rightmost bounds, inclusive
  • y2: topmost bounds, inclusive
  • w, width: bounds width
  • h, height: bounds height

Return value is in pixels.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...