Results 1 to 11 of 11

Thread: using maya api getPoints() method

  1. #1
    variable
    Join Date
    Feb 2016
    Posts
    20

    Default using maya api getPoints() method



    Hi there,

    i basically have two different shaped meshes with identical topology. I want to be able to getPoints from one mesh and setPoints onto the other mesh. The code im using the getPoints however doesn't seem to store anything. Can someone show me where im going wrong?

    Code:
    def getPoints(geo): 
    
        sel = om.MSelectionList()
        dag = om.MDagPath()
       
        sel.add(geo)
        sel.getDagPath(0,dag)
      
        mesh = om.MFnMesh(dag)
      
        vts=om.MPointArray()
        mesh.getPoints(vts, om.MSpace.kObject)
    thanks
    Sam x

  2. #2
    struct
    Join Date
    Mar 2011
    Location
    San Francisco
    Posts
    348

    Default

    Your code is correct. vts will be an MPointArray filled with the points of your mesh. What issue are you running into?

    Code:
    import maya.OpenMaya as om
    def getPoints(geo): 
    
        sel = om.MSelectionList()
        dag = om.MDagPath()
       
        sel.add(geo)
        sel.getDagPath(0,dag)
      
        mesh = om.MFnMesh(dag)
      
        vts=om.MPointArray()
        mesh.getPoints(vts, om.MSpace.kObject)
        return vts
    
    cube = cmds.polyCube(ch=False)[0]
    pts = getPoints(cube)
    for i in range(pts.length()):
        print i, pts[i].x, pts[i].y, pts[i].z
    
    0 -0.5 -0.5 0.5
    1 0.5 -0.5 0.5
    2 -0.5 0.5 0.5
    3 0.5 0.5 0.5
    4 -0.5 0.5 -0.5
    5 0.5 0.5 -0.5
    6 -0.5 -0.5 -0.5
    7 0.5 -0.5 -0.5

  3. #3
    program Theodox's Avatar
    Join Date
    Mar 2012
    Location
    Seattle
    Posts
    1,107

    Default

    May be relevant if things seem puzzling:
    http://techartsurvival.blogspot.com/...getpoints.html

  4. #4
    program Theodox's Avatar
    Join Date
    Mar 2012
    Location
    Seattle
    Posts
    1,107

    Default

    Correction - that link is for api2, it looks like your code is api 1. The Capper has it.

  5. #5
    variable
    Join Date
    Feb 2016
    Posts
    20

    Default

    ok thanks guys.

    sorry, i guess the problem i am having is a separate part of the script i didnt mention, which gets the verts of two meshes and tries to add them together, it says 'zip argument #1 must support iteration '

    Code:
    def addVerts(scan1_verts, scan2_verts):
     
        add_list=om.MFloatPointArray()
        for (v1,v2) in zip(scan1_verts,scan2_verts):
            p1=om.MFloatPoint(*v1)
            p2=om.MFloatPoint(*v2) 
            add_list.append(om.MFloatPoint(p1+p2))
    and then after this, add_list is what i want to use when i want set the points onto another mesh

    Maybe i need to get the mesh points a different way and append one by one to a list?

    thanks,
    Sam

  6. #6
    while loop
    Join Date
    Feb 2010
    Posts
    179

    Default

    What type of values are scan1_verts and scan2_verts? Are those both MFloatPointArrays?

    Because I'm fairly certain that you can't use zip with MFloatPointArrays. Just something with how the swig wrapper was setup.
    Might try this instead:
    Code:
    def addVerts(scan1_verts, scan2_verts):
     
        add_list=om.MFloatPointArray()
        for i in xrange(scan1_verts.length()):
            p1 = scan1_verts[i]
            p2 = scan2_verts[i] 
            add_list.append(om.MFloatPoint(p1+p2))
    Last edited by R.White; 12-16-2016 at 09:50 PM.

  7. #7
    program Theodox's Avatar
    Join Date
    Mar 2012
    Location
    Seattle
    Posts
    1,107

    Default

    I think Bob has it -- I don't believe that api 1 PointArray classes are complete python iterables.

  8. #8
    while loop
    Join Date
    Feb 2010
    Posts
    179

    Default

    Oh, fun fact, if you call:
    Code:
    list(om.MFloatPointArray())
    You'll kick off an infinite loop + memory leak that will do bad things to your computer. So yeah, don't do that to test whether the class is a proper itertable or not...

  9. #9
    program Theodox's Avatar
    Join Date
    Mar 2012
    Location
    Seattle
    Posts
    1,107

    Default

    FWIW I'd look at moving the whole thing over to api 2 - where the arrays act like proper iterables. In general api 2 is faster and easier to use.

  10. #10
    while loop
    Join Date
    Feb 2010
    Posts
    179

    Default

    Quote Originally Posted by Theodox View Post
    FWIW I'd look at moving the whole thing over to api 2 - where the arrays act like proper iterables. In general api 2 is faster and easier to use.
    Agreed.

  11. #11
    variable
    Join Date
    Feb 2016
    Posts
    20

    Default

    cool thanks guys. I find all this quite overwhelming so i dont think i can try and convert everything to API2 just yet. But i have got it all working with the information you've told me, thanks

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
  •