Cm to metres in Maya units

I have changed the default units in Maya from centimeters to meters. I am looking for some advice on what gotcha’s to look out for.
I have set up workflows to translate scaling issues whether I import a scene or create new objects. So not particularly worried about that aspect. What about Arnold is there any particular setting that matters for scene units?

Does anybody have any experience of things that can trip you up changing scene units?

So I have found some useful stuff.

I have a script to check on scene opened, the current unit and sets it to m if cm is detected.
Also to stop Maya setting it to cm as a default you have to set an option var, then on restart it won’t attempt to reset. Doesn’t seem to save in settings for me anyway. I found I have to script a default scene or make adjustments to camera positions and clipping planes so resetting to default positions is comfortable, in relation to the grid setup.

I was looking up the arnold manual, I found this but don’t know if there is somewhere in the UI I need to set something.

Also I used bonus tools bounding box scale to make something custom so I can quickly set say an imported object that might be 1cm bounding box to set it to 1m bounding box etc. so I won’t really worry about scale as I import geo or scenes as it will be easy to manage.

There will be lots of other bits on the way I suppose.


global proc aed_sceneOpened(){
    
    //Always set default to meters! when Maya opens up etc.
    if (`optionVar -q "workingUnitLinearDefault"` == "cm") optionVar -stringValue "workingUnitLinearDefault" "m";
    print "\n aed_sceneOpened.mel - > making sure scene units defaults to meters.";
    
    //update ui in and out.
    intField -e -v (`getAttr defaultRenderGlobals.startFrame`) AED_IF_STARTTIME;
    intField -e -v (`getAttr defaultRenderGlobals.endFrame`)   AED_IF_ENDTIME;

    //Make sure default shader present.


    //check for current units @cm and not meters.
    if(`currentUnit -q -linear` != "m") {

    aed_help "Current units in scene is not meters!";

    //PopUpWin for setting repeats.
    window -resizeToFitChildren 1 -w 350 -h 40 -t "Set scene back to meters?" AED_UI_WIN_CURRENTUNITS;
        columnLayout;
        button -w 350 -l "Set to meters" -c 
        "currentUnit -linear \"m\";\
        deleteUI -window AED_UI_WIN_CURRENTUNITS;\
        ";
    showWindow;

    }
    
    
    
    
    
    
}

If you change the units in the preferences settings window, for example to meters, and then execute the “save preferences” command, the settings will be valid only for the current scene opened in Maya. That is, when you restart Maya or create a new scene, the units settings will return to the previous ones, saved in the preferences file userPref.mel.
If you change the unit preferences (for example, to meters) and save the scene file, these settings will be saved in the scene file as a MEL command:
currentUnit -l meter;
Also, using the “scriptNode” command, it is possible to write a script to the scene file (in the section of script commands executed when opening the file), changing the units when opening the scene file.

So it is obvious that the current units in Maya and the value of the optionVar 'workingUnitLinear' parameter CAN HAVE DIFFERENT VALUES!

Python Way

# query scene unit:
maya_query_unit = cmds.currentUnit(query = True, linear = True)
# Result: 'cm'

# query scene unit (full name):
maya_query_unit = cmds.currentUnit(query = True, linear = True, fullName = True)
# Result: 'centimeter'


# set scene unit (full name):
maya_set_unit = cmds.currentUnit(linear = 'meter')
# Result: 'meter'
# or:
maya_set_unit = cmds.currentUnit(linear = 'm')
# Result: 'meter'


# get option var string value for 'workingUnitLinear':
maya_option_var_get_unit = cmds.optionVar(query = 'workingUnitLinear')
# Result: 'cm'

# set option var string value for 'workingUnitLinear':
cmds.optionVar(category = 'Settings', stringValue = ('workingUnitLinear', 'm'))

# and seved in pref file userPref.mel (-general: Save the general prefs to disk (optionVars)):
cmds.savePrefs(general = True)
# // Result: 1
# Saving preferences to : C:/Users/UserName/Documents/maya/2025/prefs/userPrefs.mel

# Result in file userPref.mel:
# ...
# // Settings
# optionVar -cat "Settings"
# -fv "positionalTolerance" 1e-08
# -sv "workingUnitLinear" "m"
# ;
# ...

MEL Way

// query scene unit:
$maya_query_unit = `currentUnit -query -linear`;
// Result: cm

// query scene unit (full name):
$maya_query_unit = `currentUnit -query -linear -fullName`;
// Result: centimeter


// set scene unit (full name):
$maya_set_unit = `currentUnit -linear "meter"`;
// Result: 'meter'
// or:
$maya_set_unit = `currentUnit -linear "m"`;
// Result: 'meter'


// get option var string value for 'workingUnitLinear':
$maya_option_var_get_unit = `optionVar -query "workingUnitLinear"`;
// Result: cm

// set option var string value for 'workingUnitLinear':
optionVar -category "Settings" -stringValue "workingUnitLinear" "m";

// and seved in pref file userPref.mel (-general: Save the general prefs to disk (optionVars)):
savePrefs -general;
// Result: 1
// Saving preferences to : C:/Users/UserName/Documents/maya/2025/prefs/userPrefs.mel

// Result in file userPref.mel:
// ...
// Settings
//optionVar -cat "Settings"
// -fv "positionalTolerance" 1e-08
// -sv "workingUnitLinear" "m"
// ;
//...

N.B.
Keep in mind that if you change the current units to centimeters, the line -sv "workingUnitLinear" "cm" will not appear/change in the preference file userPref.mel!
This is because centimeters are the default unit in Maya. And default values are usually not written to the userPref.mel preference file.

Maya Units:
default_unit = 'cm' or 'centimeter' (default)
'mm' or 'millimeter' - default_unit*0.1
'm' or 'meter' - default_unit*100.0
'km' or 'kilometer' - default_unit*100000.0
'in' or 'inch' - default_unit*2.54
'ft' or 'foot' - default_unit*30.48
'yd' or 'yard' - default_unit*91.44
'mi' or 'mile' - default_unit*160934.0

Regarding the bounding box:
Note the command: exactWorldBoundingBox

import maya.api.OpenMaya as om2

input_obj = cmds.polyCube(w=25, h=7, d=12, sx=1, sy=1, sz=1, ax=(0, 1, 0), cuv=4, ch=0)
exWBB = cmds.exactWorldBoundingBox(input_obj,
                                   ignoreInvisible = True,
                                   calculateExactly = True)
# Result: [-12.5, -3.5, -6.0, 12.5, 3.5, 6.0]

bbox = om2.MBoundingBox(om2.MPoint(exWBB[0], exWBB[1], exWBB[2], 1),
                        om2.MPoint(exWBB[3], exWBB[4], exWBB[5], 1))
# Result: maya.api.OpenMaya.MBoundingBox(maya.api.OpenMaya.MPoint(-12.5, -3.5, -6, 1), maya.api.OpenMaya.MPoint(12.5, 3.5, 6, 1))

bbox_width = bbox.width
# Result: 25.0
bbox_height = bbox.height
# Result: 7.0
bbox_depth = bbox.depth
# Result: 12.0
bbox_max_xyz = list(bbox.max)[:3]
# Result: [12.5, 3.5, 6.0]
bbox_min_xyz = list(bbox.min)[:3]
# Result: [-12.5, -3.5, -6.0]


out_bbox = 1.0
scale_factor = out_bbox/max(bbox_width, bbox_height, bbox_depth)
# Result: 0.04

cmds.scale(scale_factor, scale_factor, scale_factor, input_obj, relative = True)

exactWorldBoundingBox:
exactWorldBoundingBox command (Python)
exactWorldBoundingBox command (MEL)

optionVar:
optionVar command (Python)
optionVar command (MEL)

currentUnit:
currentUnit command (Python)
currentUnit command (MEL)

MBoundingBox
OpenMaya.MBoundingBox Class Reference

Harmony, positivity and good luck!

2 Likes

Thank you for taking the time with that extensive reply. Great information.

1 Like