Accessing Gizmos

Accessing the gizmo of a modifier (for those modifiers that have a gizmo) can be tricky. Consider this code:

my_mod = rt.UVWMap()
rt.addModifier(my_teapot, my_mod)
my_mod.gizmo.position = rt.Point3(20,20,20)

Although this works in MAXScript, in Python it produces the error: AttributeError: 'pymxs.MXSWrapperBase' object has no attribute 'gizmo'.

The reason is that the Python script does not force a scene graph evaluation the way that MAXScript does, so the gizmo is not created on the node by the time the script tries to access it. These situations can be worked around by forcing a viewport redraw, as in the following modified script:

from pymxs import runtime as rt

my_teapot = rt.teapot()
rt.convertTo(my_teapot, rt.editable_poly)
my_mod = rt.UVWMap()
rt.addModifier(my_teapot, my_mod)
rt.redrawViews() # needed to make the gizmo available
my_mod.gizmo.position = rt.Point3(20,20,20)
print(my_mod.gizmo.position)