Performing inspection and obtaining the list of classes in the Python API

The demoClassesInMaxPlus.py example demonstrates how to obtain the list of classes in the 3ds Max Python API, and the corresponding number of API elements for each class.

The inspect module provides many useful functions to obtain information about modules, classes, methods, functions and so forth. In this example, the inspect.getmembers() function is used.

To use the inspect module, you must first:

import inspect

You can use the inspect.getmembers() function with an optional predicate. If the optional predicate argument is used, then only members for which the predicate argument returns true are returned.

Using this method, you can easily obtain a list of class members by setting your predicate argument to isclass:

classes = inspect.getmembers(MaxPlus, inspect.isclass)

Using the __dict__ property

The __dict__ property is a dictionary that represents the attributes of an object. Each item is a key:value pair where the first value is the name of the attribute and the second is the value of the attribute. In this example, we use the __dict__ to obtain the name of the class and count its number of corresponding API elements:

totalcnt = 0
for c in classes:
    name = str(c[0])    
    membercnt = len(c[1].__dict__)
    totalcnt += membercnt
    api[name] = membercnt