MAYA PYTHON: Creating an LOD Group

Greetings

Does anyone know of a way to create an LOD Group in maya through script or API?

Maya’s Python Documentation shows no command for it, and currently, the only other (easy) way that I know of is using a runtime command found through echoing commands when manually creating the LOD Group. This works but requires me to add selections to my script. These selections will slow the script down so it’s less than ideal. I’m hoping someone here knows of a better way.

Thanks

maya’s lodgroups are pretty buggy to work with, specially when using them in code, the tools in the edit menu do a lot of extra stuff when connecting lods with meshes and the camera

hopefully this can help you a bit:

from maya import cmds
name = ''
children = []
distances = []
lodGrp = cmds.createNode( "lodGroup", n = name )
try:
    #connect camera to ensure visibility
    cmds.connectAttr( 'perspShape.worldMatrix', lodGrp + '.cameraMatrix', f = True )
except:
    pass
for mesh in sorted( children ):
    cmds.parent( mesh, lodGrp )
for index, attr in enumerate( distances ):
    cmds.setAttr( lodGrp + '.threshold[%s]'%index, attr )

in which children is a list of child objects and distances is a list of distances in which you want the children to swap lods