Hi Justin, Thanks for responding. Since I also filed this on Autodesk's Maya Programming forum, I've gotten a response: https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2777035
And they say it's a bug ;) You're right that if I save the return result from getFloatPoints() into a list, the MFloatPoint instances do not get changed. However, something is wrong in the way Autodesk has wrapped these methods that is incorrectly throwing away temporaries. This is especially evident in the example where I assign x, and then assign y, which changes x. On Tuesday, May 8, 2018 at 3:44:37 PM UTC-7, Justin Israel wrote: > > I think what you are seeing is the temporary reference to the > MFloatPointArray being tossed away and making your MFloatPoint reference > invalid. > Try saving the array data structure: > > sphereMeshPts = sphereMeshFn.getFloatPoints() > compareMeshPts = compareMeshFn.getFloatPoints() > sphereMeshPts[10].distanceTo(compareMeshPts[10]) > > > On Wed, May 9, 2018 at 5:52 AM Nate Reid <[email protected] <javascript:>> > wrote: > >> So, I'm seeing some very odd behavior in Maya 2017 >> (Not sure if this affects other versions, but this is the version I'm >> testing with) >> >> import maya.api.OpenMaya as om >> import maya.cmds as cmds >> sphere = cmds.polySphere(name="sphere") >> compare = cmds.polySphere(name="compare") >> cmds.xform("{}.vtx[10]".format(sphere[0]), translation=(1,1,1)) >> >> selectionList = om.MSelectionList() >> selectionList.add(sphere[0]) >> selectionList.add(compare[0]) >> sphereDagPath = selectionList.getDagPath(0) >> compareDagPath = selectionList.getDagPath(1) >> sphereMeshFn = om.MFnMesh(sphereDagPath) >> compareMeshFn = om.MFnMesh(compareDagPath) >> >> sphereMeshFn.getFloatPoints()[10].distanceTo(compareMeshFn.getFloatPoints()[10]) >> >> So, if you enter all the above in the Script Editor, and execute the last >> line, you'll sometimes get the correct answer: 2.485206365585327, and other >> times 0.0 >> So, you can test this by selecting the last line in the Script Editor, >> and press-and-hold CTRL-ENTER and watching the results go by in the Script >> Editor. >> >> If you select just the sphereMeshFn.getFloatPoints()[10]part, and >> press-and-hold CTRL-ENTER, the vertex position will not change. Similarly, >> with the compareMeshFn.getFloatPoints()[10])part >> >> If we enter these lines >> x = sphereMeshFn.getFloatPoints()[10] >> y = compareMeshFn.getFloatPoints()[10] >> >> Sometimes, the value of x will change when y is assigned. >> >> I really can't comprehend this particular behavior, and it seems like a >> bug to me. >> >> -- >> 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] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/292f92da-6f30-4a2b-9206-20eaa106a494%40googlegroups.com >> >> <https://groups.google.com/d/msgid/python_inside_maya/292f92da-6f30-4a2b-9206-20eaa106a494%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- 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/a0038e3d-184e-4d0a-aebd-f0b9ddd8f586%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
