[Closed] Setting Units to Metric
I’ve written this little script, that selects all boxes in a scene that have a specific length and width. Since I’m absolutely new to scripting, I’m glad it works, too.
Yet, here’s my problem: The scene I need the script for uses metric units, while maxscript seems to work by default in Max’s generic units. Could anyone tell me how I get my script to interpret all unit inputs as metric rather than generic?
Sorry for this absolutely noob question!
OK, you know that units are a little bizzare in max, right? They are set in one place, and can be viewed in another. So if the system unit setup says inches, and the unit setup says centimeters, max will treat every unit as one inch, but display 2.54 cm instead. So if you turn on 3d snap and activate gridpoints, you can see that 1 grid line away from the origin has a value of 25.4 cm…ie 10 units 1 inch long, then translated as cm. You probably know all this already, but I just want to be clear.
So if you make a box 10 units on a side using the snap to grid, you can see that it is 25.4 cm on a side. But if you were to try and move it that far away from the center (so to the next gridline), going ‘move $box01 [25.4, 0, 0]’ will not work correctly. It will actually move 64.516 cm. Thats because maxscript accepts system units (not generic units), where the transform typein takes display units. There is a function to calculate this backwards, though. Go ‘units.decodeValue “25.4” ’ and it will return 10 (make sure you give it a string as a parameter though…and no units in that string). This just calculates from display units to system units. So 25.4 cm is 10 inches.
Now, I am not exactly what you are going for. Do you mean that you have the display units set to metric and want to set it up so those numbers are right? because this will do that for you. But if you just want to use metric regardless of what the system and display units are, you will probably have to code a custom converter. Not sure why you would want that, though.
And of course the other option is to just set both system and display units to be the same (cm or something). Then max would be accepting your units as is.
Hope that cleared everything up! Because if you don’t know how units work, things can get very confusing
Thanks a lot!
I was actually unaware of the difference between system and display units.
Thanks for clarifying that! My script is running smoothly now.
Could have saved myself lots of trouble if I had set the system units correctly at the beginning of the project.