Max script does not work when rendering

Max script does not work when rendering

donied
Collaborator Collaborator
931 Views
6 Replies
Message 1 of 7

Max script does not work when rendering

donied
Collaborator
Collaborator
I'm using a maxscript that calculates the speed of an object. It updates text on the screen to show the speed. The max script was not written by me, it was very kindly given to me by the ML on this site. I just changed it to update text on the screen instead of a dialog.

It works fine if I type in a frame number hit return . But when I render out a number of frames the text does not update. I was wondering if anybody could tell me how to get it to update on screen when rendering. I have an animation of over 3000 frames.

I'm not a max script expert by any means but I do have programming experience in other languages.

I hope ML doesn't mind me posting it here as he has posted it on a previous post for me

--Written by ML - 2009
/* This is script is set up for metres. To change the script for different units
change the Konstant in the first line. Centimetres 0.036, mm 0.0036*/
----------------------------------------------------------------------------------------

global Konstant = 3.6
global InstantSpeed
global InstantAcceleration
global SpeedOMeter
struct noObj (name)
global ObjectToMeasure = $Car_Rig_Root

function calculateSpeed =
(
if objectToMeasure.name!="Invalid Selection" then
(
at time (currentTime-0.5f) p0 = ObjectToMeasure.position
at time (currentTime) pC = ObjectToMeasure.position
at time (currentTime+0.5f) p1 = ObjectToMeasure.position

InstantSpeed = (Konstant * framerate * (distance p1 p0))
SpeedBefore = (Konstant * framerate * (distance pC p0))
SpeedAfter = (Konstant * framerate * (distance p1 pC))

$Speed_Text.text = (InstantSpeed as integer) as string
$Speed_Text.text= (InstantSpeed as integer) as string
)
)

function assignObject =
(

/*if selection.count==1 then ObjectToMeasure = $ else ObjectToMeasure = noObj name:"Invalid Selection"*/
calculateSpeed()

)

if SpeedOMeter!=undefined then DestroyDialog SpeedOMeter

/*Turned off thee dialog by setting the size to width:0 height:0)*/
rollout SpeedOMeter "Speedometer" width:0 height:0
(
/*label lbl_Object "invalid selection" pos: width:197 height:21

GroupBox grp3 "Object" pos: width:247 height:44
GroupBox grp4 "Speed (Km/h)" pos: width:245 height:75
label lbl_Speed "Label" pos: width:93 height:17
progressBar pb1 "Speed" pos: width:233 height:15 value:100
label lbl3 "0 250" pos: width:231 height:11
label lbl7 "System Units must be Centimeters !!!" pos: width:180 height:18
label lbl5 "Acceleration (G):" pos: width:98 height:14
label lbl_accel "Label" pos: width:63 height:18 enabled:true*/





on SpeedOMeter open do
(
registerTimeCallback calculateSpeed
callbacks.addScript #selectionSetChanged "assignObject()" id:#SelectionChangeCallback
assignObject()
)
on SpeedOMeter close do
(
unRegisterTimeCallback calculateSpeed
callbacks.removeScripts #selectionSetChanged id:#SelectionChangeCallback
)
)

CreateDialog SpeedOMeter
0 Likes
932 Views
6 Replies
Replies (6)
Message 2 of 7

PiXeL_MoNKeY
Collaborator
Collaborator
Read "How do I change the text in a Text Shape dynamically?" in the maxscript help. 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
0 Likes
Message 3 of 7

Steve_Curley
Mentor
Mentor
There's an excellent (cough) example of this in this thread.
You will need to pare down your script to the bare essentials, removing everything to do with the rollouts/dialogs. If you only need to do this for 1 object then using globals may suffice.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 4 of 7

donied
Collaborator
Collaborator
Thanks lads I'll try thst.
0 Likes
Message 5 of 7

PiXeL_MoNKeY
Collaborator
Collaborator
Yes, using the same approach as the maxscript help. The maxscript help though does explain the how and why of the problem.

-Eric
0 Likes
Message 6 of 7

Steve_Curley
Mentor
Mentor
Yep - where do you think I got it from? 😉

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 7 of 7

donied
Collaborator
Collaborator
Thanks. It worked
0 Likes