Maya API Python Attribute and Type Reference

From Osipa Entertainment

Jump to: navigation, search

Contents

New to the Maya Python API? Me too. MEL Scripting, and even the scripting portions of Python are pretty easy, but the API is a different story. Often, I've found one of the most frustrating things is trying to interpret what to do when you look at available commands, and they have a bunch of "const MFloatPoint & raySource" for arguments, and determining what that is and how to send something valid can be a time-consuming adventure. Some of these need containers to be passed in so you can read their results later, some need MObjects, others can be ignored or sent simple numbers or strings. What follows is a list of very simple explanations and helpers to try and decipher it. Each section has a title like an argument you might see in the documentation, and following that you have Node Class, Node Init, Node Compute, and Def Use. These will contain, respectively, the things you'll need to add into your class, the attribute type you'll need to add to a node to "feed" this kind of argument, the translation from plug to usable argument in the compute of a node, and then how you might fill that argument in properly if used in a function. Enjoy!

  • Titles have a (r) after them if it shows a way to get a return value
  • Titles have no (r) after them if it shows how to simply get a command to run
  • I've written this as if the top of the file has import maya.OpenMaya as om

If you have any you'd like to add, please email osipa at osipaentertainment dot com, and I'll put it up here for all to have access to!

Have'em

bool <argDescrip>

Node Class

Node Init

Node Compute

a = True

or

a = False

a can now be used for an argument described by bool <argDescrip>

Def

const MFloatPoint & <argDescrip>

Node Class

INPUT = om.MObject()

Node Init

nAttr = om.MFnNumericAttribute()

<node>.INPUT = nAttr.createPoint( <longAttrName>, <shortAttrName> )

Node Compute

a = dataBlock.inputValue( <node>.INPUT )

b = a.asFloat3()

c = om.MFloatPoint( b[0], b[1], b[2] )

c can now be used for an argument described by const MFloatPoint & <argDescrip>

Def

Help!

const MFloatVector & <argDescrip>

Node Class

INPUT = om.MObject()

Node Init

nAttr = om.MFnNumericAttribute()

<node>.INPUT = n.createPoint( <longAttrName>, <shortAttrName> )

Node Compute

a = dataBlock.inputValue ( <node>.INPUT )

b = a.asFloat3()

c = om.MFloatVector ( b[0], b[1], b[2] )

d = c.normal()

d can now be used for an argument described by const MFloatVector & <argDescrip>

Def

Help!

const MIntArray * <argDescrip>

Node Class

Node Init

Node Compute

a = None

a can now be used for an argument described by const MIntArray * <argDescrip>

Def


const MTypeId & <argDescrip>

Node Class

Node Init

Node Compute

a = <put an int or enum here>

a can now be used for an argument described by const MTypeId & <argDescrip>

Def

float <argDescrip>

Node Class

INPUT = om.MObject()

Node Init

nAttr = om.MFnNumericAttribute()

<node>.INPUT = nAttr.create( <longAttrName>, <shortAttrName>, om.MFnNumericData.kFloat, 0.0 )

Node Compute

a = dataBlock.inputValue ( <node>.INPUT )

b = a.asFloat()

b can now be used for an argument described by float <argDescrip>

Def

float * <argDescrip>

Node Class

Node Init

Node Compute

a = None

a can now be used for an argument described by float * <argDescrip>

Def

int <argDescrip>

Node Class

INPUT = om.MObject()

Node Init

nAttr = om.MFnNumericAttribute()

<node>.INPUT = nAttr.create( <longAttrName>, <shortAttrName>, om.MFnNumericData.kInt )

Node Compute

a = dataBlock.inputValue ( <node>.INPUT )

b = a.asInt()

b can now be used for an argument described by int <argDescrip>

Def


int * <argDescrip>

Node Class (r)

OUTPUT = om.MObject()

Node Init (r)

nAttr = om.MFnNumericAttribute()

<node>.OUTPUT = nAttr.create ( <longAttrName>, <shortAttrName>, om.MFnNumericData.kInt, 0 )

Node Compute (r)

Before Command

outHandle = dataBlock.outputValue ( <node>.OUTPUT )

a = om.MScriptUtil().asIntPtr()

a can now be used for an argument described by int * <argDescrip>

After Command

b = om.MScriptUtil( a ).asInt()

outHandle.setInt( b )

Node Class

Node Init

Node Compute

a = None

a can now be used for an argument described by int * <argDescrip>

Def

MFloatPoint & <argDescrip>

Node Class (r)

OUTPUT = om.MObject()

Node Init (r)

nAttr = om.MFnNumericAttribute()

<node>.OUTPUT = nAttr.createPoint ( <longAttrName>, <shortAttrName> )

Node Compute (r)

a = om.MFloatPoint()

a can now be used for an argument described by MFloatPoint & <argDescrip>

Def

MMeshIsectAccelParams * <argDescrip>

Node Class

Node Init

Node Compute

a = None

a can now be used for an argument described by MMeshIsectAccelParams * <argDescrip>

Def

MSpace::Space space

Node Class

Node Init

Node Compute

om.MSpace.kWorld can be used for an argument described by MSpace::Space space

Def

Need'em

BoolOperation <argDescrip>

Node Class

Node Init

Node Compute

Def

MDagPath & <argDescrip>

Node Class

Node Init

Node Compute

Def

MIntArray & <argDescrip>

Node Class

Node Init

Node Compute

Def

MFnMesh & <argDescrip>

Node Class

Node Init

Node Compute

Def

MObject & <argDescrip>

Node Class

Node Init

Node Compute

Def

Personal tools