Notifications
Clear all

[Closed] MaxScript and Max units

I’m new to scripting and have read the forum post by Bobo on scripting units.

I am making a VrayfastSSS material via script and it needs to work in real-world human units.

Now i have my system setup in 3dsMax8 with 1 GU (generic unit) = 1cm
and I want to set my depths in world units to 0.1 cm (for instance)

I use a line:
$.material.shallow_radius = 0.1

now because I am using 1GU = 1CM it works.
But if I change the default units to 1GU = 1M or 1GU = 1 inch then the object I am applying this material to will look vastly different because of the absolute difference in the depth of light penetration.

I know I can check the units setting of the system and then make a lookup array to do the conversion with a simple function. But is there a built in function that will do the conversion for me? Or is there a way of entering data into max script and be able to specifiy the units used. I usually work in mm so I would like to be able to do something like

$.material.shallow_radius = 1 mm

(yes I know this line gives me an error).

thanks in advance for your help.

2 Replies

Look into the units struct. Specifically the units.decodeValue() function.

From the MXS online help:


units.decodeValue <string>

Parses <string> using the current unit settings and returns a <float>. A run-time error is thrown if an error occurs in the parsing of the string.

With that, you can do things like


$Box01.width = units.decodeValue "10 cm"

Hope this helps
– MartinB

ah this would be usefull