Trouble Confirming Geometry Type

Working in Maya 2022. This python code is not printing “mesh”.
I don’t get script editor error message either, just the repeated code. ???
Is it a spacing issue ?

def currentSelection(obj):
obj = cmds.ls(selection = True)
shapeNode = cmds.listRelatives(obj, shapes = True)
nodeType = cmds.nodeType(shapeNode)
if nodeType == “mesh”:
print(“mesh”)

You must be using an unknown character for your quotation marks. I get this error when running your code:

# Error: invalid character in identifier #

This works fine for me:

print("mesh")

Also keep in mind that Python allows single quotes

print('mesh')

And even triple quotes

print("""mesh""")

And you can use either the ‘’ or “” quotation marks.

As for your actual code…you might think about naming your function something more unique to what the function does. Also, you’re passing in a parameter but also finding that same parameter in a variable within the function, so the parameter really isn’t necessary. This updated version works for me:

def getMeshFromSelection():
    obj = cmds.ls(selection = True)
    shapeNode = cmds.listRelatives(obj, shapes = True)
    nodeType = cmds.nodeType(shapeNode)
    if nodeType == "mesh":
        print("mesh")

Also, hopefully I wasn’t taking it for granted but the code you pasted had no indentation. Be sure your indentation levels match and you don’t have a mix of tabs and spaces.

Hope that helps

The code being echoed / repeated in the output means that it did run. If you remove the if statement and simply do print(nodetype), do you get any output at all? If not then something else might be going on…

If the code you shared is exactly what you are running in the script editor, then it is just a definition and won’t do anything unless you call it.

def currentSelection():
    obj = cmds.ls(selection = True)
    shapeNode = cmds.listRelatives(obj, shapes = True)
    nodeType = cmds.nodeType(shapeNode)
    if nodeType == “mesh”:
        print(“mesh”)

currentSelection()

EDIT: I now noticed this post is 20 days old so you may have resolved your issue by now. Oh well