Not at a computer now but... This gets you the selected objects:
import maya.cmds as cmds
selection = cmds.ls(sl=True)
// Fredrik
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3a332d6c-0659-4d67-98e1-9b2caabeb760%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi sorry, im guessing this is a simple one. But just wanted to know the simplest way of doing this.
i want to check that the object i have selected is a polygon mesh. I assumed i had to use the 'objectType' command. but it seems you have to provide the name of the shape node of the object first. If there is a pymel way of doing it that is also fine,
any help would be great,
thanks,
Sam
here are two more ways to add to the ways listed here.
import pymel.core as pm
# pm.selected returns a list of selected items
for x in pm.selected():
# if you can get a shape node continue
if x.getShape():
# if the shapenode type is mesh then the test is good
if x.getShape().nodeType() == 'mesh':
print("Yep {0} is indeed a polygon mesh".format(x))
# returning only a list of meshes selected.
# same as above but uses a fancy pants list comprehension
justMeshes = [y for y in [ x for x in pm.selected() if x.getShape()] if y.getShape().nodeType() == 'mesh']
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/DD09D5E0-531D-4323-93CD-5AA9B9572DA0%40gmail.com.
Wow. I don’t think I’ve ever seen/used filterExpand
in any code. that’s actually quite a useful command.
I wonder how I've missed that all these years.
Thanks Justin! Always a fount of knowledge!
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABPXW4hvTXfEaQ6ZDEYjh-sM5BjC9-2NKkP3%3DkGabrgnWr3PdA%40mail.gmail.com.
cmds.filterExpand had escaped me as well. Nice!It bothers me a lot that that when you perform a query like e.g. the cmds.ls one, the return is of type list. But if there are no results, you get a return of type None. I don't know if it's just me, but I would have preferred getting an empty list back; [].
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWOytbKbp4seSGGP2_jq0uPfATLgMY9OXO%2BBYfnZV%3D4BZw%40mail.gmail.com.