Due to a miscommunication between Elsevier Press and the Python Software Foundation, the first printing of this title used an unauthorized modification of the trademarked Python logo. We apologize to the PSF for this, and they have been understanding of our in-press status; in the 2nd and subsequent printing of this title, we shall use a cover design that has been approved as non-dilutive by the Python Software Foundation.

Help make the world a better place and make a secure donation to the Python Software Foundation today!

 

Chapter 9

Understanding C++ and the API Documentation

Author

Adam Mechtley

Project

Walk through the MVector class in the API documentation

Example Files

MVector Class Documentation
MScriptUtil Class Documentation

Synopsis

This chapter introduces the Maya API and how it fits into the overall Maya architecture. We briefly describe what the API is and how it differs from the scripts that readers have written up to this point. The chapter walks readers through the C++ API’s documentation so they are able to locate information when they need it, explains how to identify what functionality is not accessible to Python, and summarizes some of the major differences between the Python and C++ APIs including the MScriptUtil and MStatus classes.

Resources

Autodesk Developer Network
Maya Python API 2.0 Documentation
Michael Comet’s Maya API Help Page
Chad Vernon’s Maya API Programming Page
Complete Maya Programming: An Extensive Guide to MEL and the C++ API

Other Notes

None

Errata for the First Edition

None


5 Responses to “Chapter 9”

  1. Hi,

    Im currently working through this book (loving the book.. ) and even started to experiment with Maya API. Im a little stuck and was wondering if someone could please help me out. Im writing a script to find the average edge length but I cant seem to get it in world space. “getLength(doublePtr, NOT SURE WHAT I NEEDS HERE)”

    import maya.cmds as mc
    import maya.mel as mm
    import maya.OpenMaya as om

    #
    #GET POLYGON SELECTION
    selection = om.MSelectionList()
    om.MGlobal.getActiveSelectionList( selection );
    iter = om.MItSelectionList ( selection, om.MFn.kGeometric );

    while not iter.isDone():
    dagPath = om.MDagPath()
    iter.getDagPath( dagPath )
    mObj = om.MObject()
    iter.getDependNode( mObj )
    dagPathHandle = dagPath.fullPathName()
    iterEdge = om.MItMeshEdge( mObj )

    while not iterEdge.isDone():
    edgeIndexListHandle =[]
    edgeIndexListHandle.append(iterEdge.index())
    print edgeIndexListHandle

    util = om.MScriptUtil()
    doublePtr = util.asDoublePtr()
    iterEdge.getLength(doublePtr)
    length = om.MScriptUtil.getDouble(doublePtr)
    print length
    iterEdge.next()
    iter.next()

    • Hi Francois,

      Looks like the second parameter for MItMeshEdge.getLength() is an MSpace (enum) value, whose default value is object space. To do world space, you should try passing om.MSpace.kWorld.

  2. When i try to pass om.MSpace.kWorld I get the following error:

    RuntimeError: (kInvalidParameter): Must have a DAG path to do world space transforms #

    Im a bit stuck on how to get this

    • When you initialize your MItMeshEdge iterator, you must pass it an MDagPath (dagPath) rather than an MObject (mObj). When you initialize with an MObject, there may be multiple paths to the object (e.g., if it is instanced) and so it needs a unique DAG path in order to know where it is in world space.

  3. Thanks Adam that did the trick

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>