Problem Confirming Mesh Type

Problem Confirming Mesh Type

bayareadeck
Enthusiast Enthusiast
433 Views
3 Replies
Message 1 of 4

Problem Confirming Mesh Type

bayareadeck
Enthusiast
Enthusiast

Working in Maya 2022.  This python code is not printing "mesh".

I don't get an 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")

434 Views
3 Replies
Replies (3)
Message 2 of 4

Kahylan
Advisor
Advisor

Hi!

 

You are just storing your function into Memory but not calling it currently.
You need to add:

currentSelection()

 

At the end, to actually execute your fuction. Also your kwarg "obj" in your functions definition is redundant because you immediately overwrite it. 

I would probably define another attribute, like this:

selObj = cmds.ls(selection = True)or obj

 

This gives the user the ability to define the obj via string in when calling the function if nothing is selected.

 

I hope this helps!

0 Likes
Message 3 of 4

bayareadeck
Enthusiast
Enthusiast

Ok, right of course.... like this ? it is compiling. Thank you!

 

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

currentSelection()

0 Likes
Message 4 of 4

Kahylan
Advisor
Advisor

Exacly!

 

Have a nice day

0 Likes