[Closed] Converting numbers to world units?
Hey Guys,
Im trying to convert 10meters to world units in max.
For example i want to set the size of a dummy to 10meters doing
$.boxsize = [10,10,10] is not 10meters, its 10 “max” units.
This works fine if i use a spinner set to world units however. So there must be some easy way to convert 10meters to max units?
Cheers
I hope you understand how generic units vs. system units work.
You can easily set a spinner to show world units, or convert a value to the user display units AS A STRING to display somewhere. But if you want to make a box that corresponds to size of 10 meters, you will have to find out what the system units are set to (could be inches, feet, cm, meters etc.), see how many of these is one generic unit equal to, do some multiplications and get the final result.
For example, if your System Units are set to 1GU = 1cm, obviously you have 100 GU = 1 m, and thus you will need 10 * 100 = 1000 generic units to represent 10 meters.
If the system units are set to 1 GU = 1 inch, you have to figure out how many inches are there in 10 m. 1 inch = 2.54 cm. 100 cm = 1 meter. So there are 39.37 inches in a meter, and for 10 meters, you need 393.7 inches (which are the same as Generic Units at these settings).
You can write a function that can convert between feet, inches, miles and all the metric units and then just pass a value in any units and get the generic units it corresponds to according to the current system unit settings.
I will leave the fun to you…
I lied.
There IS a function to return the value:
units.decodeValue “10.0m”
–>393.701 –this is the result from 1 GU = 1 inch.
Here is a MAXScript function that returns the number of meters in one generic unit.
To see how many generic units you need to represent 10 meters, just divide 10 by the result of the function.
fn GetMetersFromGU =
(
meters = case units.systemType of
(
#Inches: 0.0254
#Feet: 0.3048
#Miles: 1609.0
#Millimeters: 0.001
#Centimeters: 0.01
#Meters: 1.0
#Kilometers: 1000.0
)
meters*units.SystemScale
)
10.0 / (GetMetersFromGU())
–>393.701 –this is the result from 1 GU = 1 inch.
See? Same result.
sweet! thanks again Bobo!
Yeah I was thinking of doing a function, however I just wanted to check if there was an easy way to do it first