Writing it using the maya Python 2.0 API might make it simpler though as the array types can be iterated over much more easily.
On Wednesday, 8 October 2014 17:02:23 UTC+1, Jack Straw wrote: > > Heres a little bit of code to print out the corrdinates; > > intersections = returnCollisionPoints() > for pnt_idx in range(intersections.length()): > print intersections[pnt_idx][0], intersections[pnt_idx][1], > intersections[pnt_idx][4] > > Writing it using the Python 2.0 API > > On Wednesday, 8 October 2014 14:17:47 UTC+1, [email protected] wrote: >> >> Hi, >> >> am struggling a little with MfnMesh stuff. I have the coords of a point >> in space and i want to be able to fire off a vector from this point with >> direction in negative x. and then i want the script to print the coords of >> any collision points with a mesh. >> >> here is some code i found which comes very close to solving it. but im >> just not smart enough to adapt slightly. >> >> create a polySphere and run this: >> ######################################### >> >> import maya.cmds as cmds >> import maya.OpenMaya as om >> >> def returnCollisionPoints(point=(10.0,2.0,3.0), dir=(-1.0, 0.0, 0.0)): >> sel = om.MSelectionList() >> dag = om.MDagPath() >> >> #replace torus with arbitrary shape name >> sel.add("pSphereShape1") >> sel.getDagPath(0,dag) >> >> mesh = om.MFnMesh(dag) >> >> point = om.MFloatPoint(*point) >> dir = om.MFloatVector(*dir) >> hitPoints = om.MFloatPointArray() >> >> mesh.allIntersections( >> point, dir, >> None, None, >> False, om.MSpace.kWorld, >> 10000, False, >> None, >> None, >> hitPoints, >> None, None, >> None, None, >> None >> ) >> return hitPoints >> >> print returnCollisionPoints() >> ################################################ >> >> so it to be able to print out hitPoints as coordinates i guess. Does >> anyone know how to do this? >> >> thanks alot, >> Sam >> >> -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/92c8f78b-727d-43a6-9d9e-483a92d68053%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
