Python for 3ds max – Select objects of type

Software:
3ds max 2020

Continuing this example,
If you need to select objects (nodes) of a certain type i.e. lights, cameras etc.
You can use the INode class’s GetObject() method to get a reference to the node’s object, or “modified object” in 3ds max terms, and use the object’s GetSuperClassID() method to get the integer id representing the object’s superclass.

In addition, the MaxPlus SuperClassIds class contains convenient constants that can be used to avoid having to check and remember the superclasses numeric ids.
See reference here:
https://help.autodesk.com/view/3DSMAX/2017/ENU/?guid=__py_ref_class_max_plus_1_1_super_class_ids_html

An example of a script that selects all light objects in the scene:

from MaxPlus import SuperClassIds
from MaxPlus import SelectionManager

def scene_objects():
   def list_children(node):
      list = []
      for c in node.Children:
         list.append(c)
         list = list + list_children(c)
      return list
   return list_children(MaxPlus.Core.GetRootNode())

for o in scene_objects():
   obj = o.GetObject()
   if obj.GetSuperClassID() == SuperClassIds.Light:
      SelectionManager.SelectNode(o, False)

* note that when copying and pasting a script from this example, the indentation may not be pasted correctly.

4 thoughts on “Python for 3ds max – Select objects of type

  1. If you wanted to do it all in the pymxs api instead of using maxplus you could do it this way btw:

    import pymxs
    rt = pymxs.runtime

    # find exportable as the node has geom somewhere
    def get_all_children(parent, node_type=None):
    def list_children(node):
    children = []
    for c in node.Children:
    children.append(c)
    children = children + list_children(c)
    return children
    child_list = list_children(parent)

    return ([x for x in child_list if rt.superClassOf(x) == node_type]
    if node_type else child_list)

    # getting only the first selected item
    sel = rt.getCurrentSelection()[0]
    kids = get_all_children(sel, rt.GeometryClass)
    # lights would be
    # kids = get_all_children(sel, rt.light)

    You could of course move the type filtering out like you have as well, but I thought this would be a handy thing 🙂

Leave a Reply