Results 1 to 4 of 4

Thread: Maya API in Python - MItMeshPolygon.getIndex()

  1. #1
    float dbsmith's Avatar
    Join Date
    Aug 2009
    Location
    Wellington, New Zealand
    Posts
    79

    Default Maya API in Python - MItMeshPolygon.getIndex()



    Argh, i cannot get this method to work!
    Code:

    Code:
    polygonIter = maya.OpenMaya.MItMeshPolygon(myObject)
    faceIndex = 0
    
    scriptUtil = maya.OpenMaya.MScriptUtil()
    scriptUtil.createFromInt(0)
    dummyIndex = scriptUtil.asIntPtr()
    
    polygonIter.setIndex(faceIndex, dummyIndex)
    And the error:
    # polygonIter.setIndex(faceIndex, dummyIndex)
    # File "D:\buildforge\Maya_2011_Win64_Build\build\wrk\opt im\runTime\Python\Lib\site-packages\maya\OpenMaya.py", line 6367, in setIndex
    # TypeError: in method 'MItMeshPolygon_setIndex', argument 2 of type 'int' #

    The parameter docs say this:
    MStatus MItMeshPolygon::setIndex(int index, int & prevIndex)

    [in] index The index of desired face to access.
    [in] prevIndex The index of the current face in the iteration

    Why prevIndex is needed is beyond me, and why its an int & is also baffling...

    Any ideas? Cheers!

  2. #2

    Default

    Your code executes for me pretty much as written (I subbed in my own MObject, obviously).

    That makes me think that your faceIndex is getting messed with, somehow. Either you haven't supplied us with all the code or there's some background script running that may have changed its value.

  3. #3
    float dbsmith's Avatar
    Join Date
    Aug 2009
    Location
    Wellington, New Zealand
    Posts
    79

    Default

    Cheers for testing this Bronwen.
    Well, the only other code of relevance really is turning my polygonal object into an MObject. Is your MObject a component or something like that?

    I found a workaround, which essentially just uses an iterator to loop through all the object's faces, and ignoring those indices which i don't care about.

  4. #4
    Sr Environment Artist greuh's Avatar
    Join Date
    Jul 2008
    Location
    Montreal
    Posts
    64

    Default

    I've had to do some setIndex of my own not too long ago, and had to deal with similar issues trying to wrap all that MScriptUtil nonsense. While I can't really comment as to why your code is not working, here's what ended up working for me, hopefully it helps you sorting out your problem.
    Only real difference I can see is the MItMeshPolygon constructor we are using.

    Code:
    comp = api.MObject()
    
    area = api.MScriptUtil()
    area.createFromDouble(0.0)
    areaPtr = area.asDoublePtr()
            
    dummy = api.MScriptUtil()
    
    currentFace = api.MItMeshPolygon( self.dagPath, comp )
    currentFace.setIndex(self.faceID, dummy.asIntPtr())
    currentFace.getArea(areaPtr,api.MSpace.kWorld )
    self.dagPath & self.faceID are variables created somewhere else matching a specific object and a face ID in this object.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •