subtracting coordinate values from seperate lists python API

51 views
Skip to first unread message

s...@weacceptyou.com

unread,
Dec 9, 2016, 9:47:01 AM12/9/16
to Python Programming for Autodesk Maya
hello i have some python code that subtracts corresponding coordinates from two separate lists and then appends the result to a new list:

def findDiff(scan1_verts, scan2_verts):

diff_list=[]

for (v1,v2) in zip(scan2_verts,scan1_verts):
diff=(v1[0]-v2[0]),(v1[1]-v2[1]),(v1[2]-v2[2])
diff_list.append(diff)

return diff_list

what i want to know is if this can be done easily with the maya python API. I later want to use setPoints to set the verts of a new piece of mesh with this list. so for that reason i think they need to be OpenMaya.MFloatPoint values or something.

sorry im so confused by how the API does things. If someone could show me how to set it up i would really appreciate it.

thanks,
Sam

Justin Israel

unread,
Dec 9, 2016, 10:53:21 PM12/9/16
to python_in...@googlegroups.com
Have you read up on the MFloatPoint in the docs? It shouldn't be too confusing to use. 

Assuming your verts are normal tuples and you want to convert them to MFloatPoint,

import maya.OpenMaya as om

def findDiff(scan1_verts, scan2_verts):
    diff_list = om.MFloatPointArray()

    for v1, v2 in zip(scan2_verts, scan1_verts):
        p1 = om.MFloatPoint(*v1)
        p2 = om.MFloatPoint(*v2)
        diff_list.append(om.MFloatPoint(p2 - p1))

    return diff_list

Justin


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c471cb79-878e-4ab5-b75c-3ec1f79711a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

s...@weacceptyou.com

unread,
Dec 14, 2016, 7:35:43 AM12/14/16
to Python Programming for Autodesk Maya
Thanks Justin,

I did read this page. But i still find it hard to make sense of how things are worded sometimes. Ill try and learn from this example

thanks,
Sam
Reply all
Reply to author
Forward
0 new messages