How to output a dynamic variable?

This is a mechanical system i simulated on 3ds max. I had made a maxscript to output the angle of rotation of the cylinder shown in picture to external files. But the problem is that i need to output the angle of rotation in real time, meaning that when i rotate the cylinder, the outputted data updated the data in real time, just like what happen at the status bar(the coordinate input section which is marked red in the picture). Can anyone tell me how to output a dynamic variable (in this case is angle of rotation)? Or read the dynamic variable at the coordinate input section?

AttachmentSize
angle.png73.38 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
wingwingwing's picture

Thx for everyone's help! Now

Thx for everyone's help!
Now i can output the variable either when transform or animate!

the maxscript code i use as followed:

a=$cylinder01
b=$cylinder02
c=$cylinder03
d=$cylinder04

fs= createfile "C:\\Users\\User\\Desktop\\rotation angles1.txt"
when transform a changes handleAt:#redrawViews do (in coordsys parent format "rotation-y cylinder 01 = %\n" a.rotation.y_rotation to: fs )

fn time_cb = in coordsys parent format "rotation-y cylinder 01 = %\n" a.rotation.y_rotation to: fs
fn tcb = time_cb()
registerTimeCallback tcb

fs1= createfile "C:\\Users\\User\\Desktop\\rotation angles2.txt"
when transform b changes handleAt:#redrawViews do (in coordsys parent format "rotation-z cylinder 02 = %\n" b.rotation.z_rotation to: fs1 )

fn time_cb = in coordsys parent format "rotation-z cylinder 02 = %\n" b.rotation.z_rotation to: fs1
fn tcb = time_cb()
registerTimeCallback tcb

fs2= createfile "C:\\Users\\User\\Desktop\\rotation angles3.txt"
when transform c changes handleAt:#redrawViews do (in coordsys parent format "rotation-z cylinder 03 = %\n" c.rotation.z_rotation to: fs2 )

fn time_cb = in coordsys parent format "rotation-z cylinder 03 = %\n" c.rotation.z_rotation to: fs2
fn tcb = time_cb()
registerTimeCallback tcb

fs3= createfile "C:\\Users\\User\\Desktop\\rotation angles4.txt"
when transform d changes handleAt:#redrawViews do (in coordsys world format "rotation-z cylinder 04 = %\n" d.rotation.z_rotation to: fs3 )

fn time_cb = in coordsys parent format "rotation-z cylinder 04 = %\n" d.rotation.z_rotation to: fs3
fn tcb = time_cb()
registerTimeCallback tcb

But now the problem is that when i use the script above, i can only get the last files outputed, the other 3 earlier's text files is blank!

What should i do? is it i should make a loop or something else?
Can someone give example on how to fix this?

Anubis's picture

You overwrite the same named

You overwrite the same named function 4 times, their is why works only the last one.

-------- FiX_variant_1:
fn time_cb_1 = ...
registerTimeCallback time_cb_1
fn time_cb_2 = ...
registerTimeCallback time_cb_2
fn time_cb_3 = ...
registerTimeCallback time_cb_3
fn time_cb_4 = ...
registerTimeCallback time_cb_4
 
-------- FiX_variant_2: (pack all in one function)
fn time_cb = (
    in coordsys parent format "rotation-y cylinder 01 = %\n" a.rotation.y_rotation to:fs
    in coordsys parent format "rotation-z cylinder 02 = %\n" a.rotation.z_rotation to:fs1
    in coordsys parent format "rotation-z cylinder 03 = %\n" a.rotation.z_rotation to:fs2
    in coordsys parent format "rotation-z cylinder 04 = %\n" a.rotation.z_rotation to:fs3
)
registerTimeCallback time_cb

my recent MAXScripts RSS (archive here)

wingwingwing's picture

It worked! Thank! You are my

It worked!
Thank! You are my Messiah!

Graph's picture

if we knew what ur trying to

if we knew what ur trying to do we might be more helpfull :P

Raphael 'Insanto' Steves
http://Graph.Net84.Net

Anubis's picture

may be wiring params (w/o

may be wiring params (w/o output data to file) ?

[edit] Hi Wing, I was receive a mail from you (it was in spam) :) n/m I mean menu Animation / Wire Parameters, but of course I can only guess about the final goal of your script.

Cheers,
Anubis

my recent MAXScripts RSS (archive here)

le1setreter's picture

have a look in the max help

have a look in the max help for "Change Handlers and When Constructs":

a little example:

when transform $Box01 change do (
 
	myX = $Box01.position.X
	print myX as string
 
)
wingwingwing's picture

I tried ur suggestion and it

I tried ur suggestion and it works!!

this is the code i used at this moment:

a=$cylinder01
fs= createfile "C:\\Users\\User\\Desktop\\source code5.txt"
when transform a changes do
(
in coordsys parent format "rotation-y cylinder 01 = %\n" a.rotation.y_rotation to: fs

)

and the result is as followed when i rotate the object:

rotation-y cylinder 01 = 27.9907
rotation-y cylinder 01 = 26.6364
rotation-y cylinder 01 = 27.9907
rotation-y cylinder 01 = -4.65485
rotation-y cylinder 01 = 27.9907
rotation-y cylinder 01 = -14.9164
rotation-y cylinder 01 = 27.9907
rotation-y cylinder 01 = -15.7972
rotation-y cylinder 01 = 27.9907
rotation-y cylinder 01 = -16.678
rotation-y cylinder 01 = 27.9907
rotation-y cylinder 01 = -17.5588
rotation-y cylinder 01 = 27.9907
rotation-y cylinder 01 = -19.3535
rotation-y cylinder 01 = 27.9907
rotation-y cylinder 01 = -20.6747
rotation-y cylinder 01 = 27.9907

The code worked but it repeated the first angle it recorded as well, any idea on how to solve this bug?
i troubleshooting for few days already and i still dont know why the bug still there.

Anubis's picture

Hi, I wonder how your script

Hi, I wonder how your script work w/o openFile() function.

newFile = createFile "C:\\temp\\test.txt"
fs = openFile newFile mode:"at" -- write-only text, append writes - file must exist
fs = openFile newFile mode:"wt" -- write-only text - deletes file contents if it exists

For more infos see the openFile() function into the help.

my recent MAXScripts RSS (archive here)

Graph's picture

$.rotation ? quatToEuler

$.rotation ?

quatToEuler $.rotation ?

print $.rotation ?

registerRedrawViewsCallback theFN ?

Raphael 'Insanto' Steves
http://Graph.Net84.Net

wingwingwing's picture

toolmode.coordsys

toolmode.coordsys #parent
a=$cylinder01
b=$cylinder02
fs= createfile "C:\\source code5.txt"
fs1= createfile "C:\\source code6.txt"
in coordsys parent format "rotation-y cylinder 01 = %" a.rotation.y_rotation to: fs
in coordsys parent format "rotation-z cylinder 02 = %" b.rotation.z_rotation to: fs1
x= in coordsys parent a.rotation.y_rotation
y= in coordsys parent b.rotation.z_rotation

I want to output my x and y in dynamic value, in which the variable(rotation angle) change in real time when i simulate the system in 3ds max(the rotation angle outputted dynamically when the animation run). How?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.