[Closed] Dynamically changing spline text value
Hi… I hope someone can help me.
I am trying to figure out how to run a script I made DURING the rendering. I notice that I can either call the script before OR after the rendering process but is there a way to call it while the animation is being rendered? I have a script that would change the value of a spline text, but once the script is done, it only saves the last value that I set the text to. FYI the text I want to display is the x-position of a moving sphere.
Another way to ask the question might be: Is there any way I can change a spline text value dynamically?
put a script controller at text’s scale track, like this:
$Text01.text = $Sphere01.pos.x as string
[1, 1, 1]
I’d assign the text as a node though. e.g
test = $test
sphere = $sphere01
test.text = (sphere.pos.controller.value as string)
Look up “How do I change the text in a Text Shape dynamically?” in the MAXScript Reference. From that page:
Normally, the text of a Text shape is not animatable. The resulting mesh will be evaluated once at the beginning of the rendering and will not change as it is considered static (not changing over time). A workaround is to assign a script controller to a property of the text shape which will do two things: tell the renderer that the text shape is animated and thus requires reevaluation on each frame, and set the actual text in the text property.
-Eric[color=white][/color]
I added this code on the Script Controller in my Text Spline but I keep getting a:
Type error: dependsOn needs a MaxWrapper arg, got: OK
dependsOn $Text02 $Sphere02{
testText = ($Sphere02.position.x) as string
setAppData $Text02 1 testText
}
ok so I have the text value changing as I want it to [i know because when I move the slider, the text changes] but as soon as I render, 3dsmax crashes right after the first frame. Is there some reason why it does this?
Did you assign the script controller to the .kerning track as suggested in the Reference?
To continue the quote,
[left][color=red]WARNING: [/color]
[/left]
[left]Changing the text object’s text property in anything other than a controller applied to the text object can lead to a renderer crash!
[/left]
I just pasted the code from the Reference into Max 9, added a MeshSelect on top of the text and it rendered without problems.
Also, NEVER EVER use curly brackets {} in MAXScript unless you are defining a bitarray. Only round parentheses ( ) are supported.
t = $Text02
t.baseobject.renderable = true
t.kerning.controller = float_script()
scrpt = "dependsOn $Sphere02.position.x
t.text = ($Sphere02.position.x) as string
0"
t.kerning.controller.script=scrpt
I have this now. But it gives me an Unknown property “kerning” in 0.0 error.
You cannot use the variable t inside the scripted controller. It is defined as global variable only when you first run the script but would be undefined if you restart Max and load the scene again. On top of that, “T” is a reserved local variable inside every Scripted controller and has the current TIME value stored in it. You have to use the name of the text object inside the script, as shown in the Reference, for example
t = $Text02
t.baseobject.renderable = true
t.kerning.controller = float_script()
scrpt = "dependsOn $Sphere02.position.controller;
$Text02.text = ($Sphere02.position.x) as string
0"
t.kerning.controller.script=scrpt
According to your error message, somewhere along the road the variable t became equal to 0.0 and then did not have a .kerning property. But you did not tell us WHEN do you get the error – when you run the script or when you update the animation to see the scripted controller…
The dependsOn cannot be set to .position.x because that is a VALUE. You need a controller or node to be dependent on.
I just run the above code having a Text02 and a Sphere02 in the scene and the text was updating when the sphere was moving… It renders ok, too.
Hi, Bobo. I was wondering if you can clear something up for me.
First thing’s first; I have no scripting experience whatsoever.
I was trying to create an LCD Display (for outputting the speed of a moving vehicle)at work today and realized that I can’t change the text dynamically; so I came across this thread. I tried your code/method and it seems to be working and it doesn’t crash during rendering (locally, if it matters). But, I did get an error during evaluating the script. I just want to be sure it will work fine and I won’t come across any problems in the long run.
These are the steps I took:
created the text
created a sphere
assigned a script controller/scale script to the object
popped in your code in the properties window for the scale script
renamed the object names in the script to match my scenes object names
So, it all works great. But this is the error I get:
– Unable to convert: “dependsOn $Sphere01.position.controller;
$Text01.text = ($Sphere01.position.x) as string
0” to type: Point3
Should I be concerned about this?
Also, is there any way to output the numbers to something like “000.00”? Currently, the returned values jump around from something like “1.234” to “5.23456.” Is there a way the keep the number of integers after the dot to be consistent?
Sorry if I sound like a complete noob. Any help would be greatly appreciated. Thanks a lot.
btw, I know I could just make a texture map with After Effects instead of going through all this trouble, but it is very interesting to me to make it work in Max.
Sorry for the late answer, I totally missed the message.
A Script Controller MUST return a value matching the value of the track it is assigned to. A Scale Controller should return [1,1,1] for the object to appear 100% scaled. My example was returning a single value because it was using a different controller (the Kerning) which expects a single float.
As for the formatting, yes, 3ds Max 9 and higher support a formattedPrint() method that can be used to define the number of leading and trailing zeros among other things. In previous versions, there was a plugin extension with the same functionality.
didn’t test rendering with script at scale track, but yes, crashes immediately. Moving script to kerning fixed it
Thanks for the info, and just to append, I had a script going that was crashing on render because I was changing extruded text values, and you don’t even have to move the whole script to kerning. If you just assign a controller to the kerning MAX will recognize the need to update the geometry and not crash. Thats my experience anyway, it renders fine now and all I did was add this line:
$.kerning.controller = float_script()
to each dynamically updated text object.