View Full Version : Auto update spline Text with a Tape Helper length?
onitreb 06-01-2009, 09:22 PM I want to create a visual label on a tape helper, so I can always see how long the tape is. I want to use a spline Text to do this.
This is ostensibly simple, but I don't know how to cause the text to update whenever the Tape's length changes. Can an expression do this? I'm a Newbie for sure. Please talk to me like I am a child.
I got this far:
$Text01.text = $Tape01.length as string
or
$Text01.text = (distance $Tape01 $Tape01.target) as string
I was going to try to attach a script controller to text.text but it is not available in the graph editor!
Thanks for the help!
|
|
PiXeL_MoNKeY
06-02-2009, 03:35 AM
There is some information on this in the MaxScript FAQs "How do I change the text in a Text Shape dynamically?". Basically you need to assign a script controller to a parameter of the text object which is a constant value, and run your code inside that. Also, you shouldn't need the depends on part.
1) Assign script controller to kerning.
2) Create a variable (tapeObj, or whatever you want it called) assign the Tape node to it
3) Create another one (textObj) and assign your text node to it
4) Your code would be something like:textObj.text = (distance tapeObj tapeObj.target) as string -- code for the updating text
0 -- value that will be returned for kerningNOTE: the distance output will be in generic units so you will need to do the mathematical conversion to get your default unit of measure.
-Eric
onitreb
06-03-2009, 07:17 PM
Wow, thanks for plugging some holes in my knowledge!
It works awesomely!
2 things I needed to understand - which might help other noobs:
You can't (correct me if I'm wrong) create variables on the fly in the Expression of a Script Controller - they have to be created under "create variable".
And you need that 0 at the end of the expression to please max, or else it will be confused by the string your expression outputs because Kerning requires an integer/float.
Thanks so much!
Wow, thanks for plugging some holes in my knowledge!
It works awesomely!
2 things I needed to understand - which might help other noobs:
You can't (correct me if I'm wrong) create variables on the fly in the Expression of a Script Controller - they have to be created under "create variable".
And you need that 0 at the end of the expression to please max, or else it will be confused by the string your expression outputs because Kerning requires an integer/float.
Thanks so much!
You can create variables in Script Controllers, but they will be local.
The "variables" you create in Expression and Script Controllers are actually Parameters stored in a Parameter Block (similar to how Max Plugins and MAXScript Custom Attributes manage their parameters). Thus, if you assign a node reference or a controller to one of them, the reference will be handled by the same mechanism that manages dependencies and notifications inside of Max. For example, if you rename a scene object being referenced, it won't break the connection and the controller will still work.
As for the 0, yes, the last value evaluated in the code is returned as the result and since the controller is assigned to the Kerning, you have to provide some plausible value to avoid an error.
Note that you can use units.formatValue() to convert the generic units value to the current User Units.
onitreb
06-03-2009, 08:52 PM
Awesome! Thanks for the extra clarification.
units.formatValue works great, too.
CGTalk Moderation
06-03-2009, 08:52 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.