Message 1 of 7
Max script does not work when rendering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
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