Creating Custom Attributes with pymxs

You can access existing custom attributes in pymxs using the MAXScript custAttributes struct. However, you cannot define and create custom attributes natively using pymxs. You can do so by defining custom attributes in a string of MAXScript code, and then executing it using pymxs.runtime.execute().

This example defines a custom attribute on a teapot, later setting its value:

import pymxs
mxs=pymxs.runtime

mxs.resetMaxFile(mxs.Name('noPrompt'))

# set up a custom attribute on the teapot
# this is just a string of MAXScript

testCAcmd='''attributes "TestCustAttrib"
(
    parameters main rollout:params
    (
        param1 type:#float ui:spinParam1 default:10 animateable:True
    )

    rollout params "Test Parameters"
    (
        spinner spinParam1 "Param1" type:#float
    )
)'''

attr = mxs.execute(testCAcmd)

# we can now add the custom attribute to scene objects
t = mxs.teapot()
mxs.custAttributes.add(t.baseObject, attr)

# and set values on it
t.TestCustAttrib.param1 = 21