Error: MFnMesh : no matching constructor found

Error: MFnMesh : no matching constructor found

ashwithullal
Participant Participant
1,215 Views
2 Replies
Message 1 of 3

Error: MFnMesh : no matching constructor found

ashwithullal
Participant
Participant

I tried running this script on maya2022, but I am stuck with this error. 
I created two spheres in the scene as a test and wanted to check the surface collusion using this script. ended up with the error which I have pasted below.


import maya.api.OpenMaya as OpenMaya

surface1_name = "pSphere1"
surface1_fn = OpenMaya.MFnMesh(surface1_name)

surface2_name = "pSphere2"
surface2_fn = OpenMaya.MFnMesh(surface2_name)

are_colliding = surface1_fn.collide(surface2_fn)

if are_colliding:
print("The surfaces are colliding")
else:
print("The surfaces are not colliding")

 

# Error: MFnMesh : no matching constructor found
# Traceback (most recent call last):
# File "<maya console>", line 4, in <module>
# ValueError: MFnMesh : no matching constructor found #

 

 

Kindly let me know the way forward

0 Likes
1,216 Views
2 Replies
Replies (2)
Message 2 of 3

BurkhardRammner
Collaborator
Collaborator

I don't script in Python.

But in C++ there is no constructor for MFnMesh with a string as an argument.... I assume that Python doesn't have such a constructor either...

0 Likes
Message 3 of 3

jonathan_ouellet
Contributor
Contributor

You have to use MSelectionList to get the dagpath instance from the object name

 

from maya.api import OpenMaya as om

sel = om.MSelectionList()
sel.add("objectName")
mfnMesh = om.MFnMesh(sel.getDagPath(0))