You can import a specific class from MaxPlus, instead of the entire MaxPlus module, into the current namespace. For example, you can do as follows:
from MaxPlus import Point3 as MyPoint3
for item in dir(MyPoint3):
print item
This example shows how you can expose only the Point3 class of MaxPlus, and how to rename it as you like.
You can obtain a list of attributes for a class (list of methods, variables) using help
as follows:
import MaxPlus
help(MaxPlus.Asset)
In your MAXScript Listener window, you will obtain a list of all attributes for the Asset
class.
To find information on the object that a Python command has created, use type
and help
together. In the demoActionFactory.py
example, you can find information on the object that MaxPlus.ActionFactory.Create
has created by adding the help
statement as follows :
action = MaxPlus.ActionFactory.Create('Do something', 'Python demo', doSomething)
help(type(action))
To obtain a list of attributes and their corresponding values, you can also use the Python built-in dir()
and getattr()
functions. For example, you add the following statements to demoActionFactory.py
:
action = MaxPlus.ActionFactory.Create('Do something', 'Python demo', doSomething)
at = type(action)
for k in dir(at):
print "I have an attribute named ", k, " which has a value, ", getattr(action, k)
The dir(object)
function, when passed an argument (object), returns a list of attributes for the object.
The getattr(object, name)
function returns the value of the named attribute of the object.
There are a number of classes that are enumerable. That is, they support the for
statement. For example, you can do as follows:
import MaxPlus
xs = MaxPlus.IntList()
xs.Append(3)
xs.Append(4)
xs.Append(5)
for x in xs:
print x
Some of these classes include lists such as: Point3List
, Point4List
, StrList
, ReferenceTargetList
, IntList
, FloatList
and so forth.
You can create an exclusion list, for example, so that specific nodes are excluded from being illuminated by a light. Create an exclusion list for your object (for example, your light) using ParameterBlock.excludeList
. Then create a node for the object that you want to exclude and append the node to the exclude list. An example is as follows:
import MaxPlus
#Create your light
obj = MaxPlus.Factory.CreateOmniLight()
#Create an exclusion list for your light
excludeList = obj.ParameterBlock.excludeList
v = excludeList.Value
#Create a node for the object you want to exclude
node = MaxPlus.Factory.CreateNode(MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Cone))
#Append the node to the exclude list
v.Append(node)
#Tie the exclude list back to the Value property
excludeList.Value = v
#Create a node for your light object
LightNode = MaxPlus.Factory.CreateNode(obj)
Now if you select LightNode
, then click Exclude in the Modify panel in the UI, you can see that the cone belongs to the light's exclusion list.
TipYou can select a node by using the INode.Select()
method; for example LightNode.Select()
will select the light node you just created in the above example.
Many methods take a TimeValue
parameter. You can use Core.GetCurrentTime()
to obtain the current time to provide to these methods.
You can access custom attributes on an object by executing some MAXScript, and using the returned FPValue:
eval_str = "custAttributes.getPBlockDefs (custAttributes.getDef $Sphere001 1)"
r = MaxPlus.Core.EvalMAXScript(eval_str)
print MaxPlus.FPTypeGetName(r.Type)
print r.Get()