difference between pymel selection and python selection

150 views
Skip to first unread message

e955...@gmail.com

unread,
Sep 26, 2014, 6:44:20 PM9/26/14
to python_in...@googlegroups.com
Hi there,

can anyone tell me the difference between these two commands, one in pymel and the other in python. I thought they both just returned the Transform name of the object selected. But apparently not.

if you create a poly sphere and run this

###########################################

import maya.cmds as cmds
import pymel.core as pm

mesh=pm.selected()[0]
print "mesh1: ", mesh

mesh=(cmds.ls(selection=True)[0])
print "mesh2: ", mesh

############################################

they return the same name but can't be used interchangeably it seems, can anyone help?

thanks,
Sam

Justin Israel

unread,
Sep 26, 2014, 6:49:42 PM9/26/14
to python_in...@googlegroups.com

The native Maya cmds module deals in terms of string paths as the identifiers. pymel is an abstraction layer that creates a node object with methods.

--
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/ef3776e8-0e39-414b-addf-e24dd649c636%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin Israel

unread,
Sep 26, 2014, 6:59:27 PM9/26/14
to python_in...@googlegroups.com
Oh and if you are wondering why when you print them, they both look like they might be the same, it is because the pymel nodes define __str__() and __repr__() methods:

You are just comparing the string conversion of the two different approaches. But one is actually a unicode object and the other is am instance PyNode subclass. 

e955...@gmail.com

unread,
Sep 27, 2014, 5:26:12 AM9/27/14
to python_in...@googlegroups.com
cool thankyou Justin,
i knew there was something more to this ha ,

thanks,
Sam

e955...@gmail.com

unread,
Sep 27, 2014, 5:29:50 AM9/27/14
to python_in...@googlegroups.com, e955...@gmail.com
oh wait, but is there a way to achieve the same node object through python only?

thanks,
Sam

Justin Israel

unread,
Sep 27, 2014, 7:11:38 AM9/27/14
to python_in...@googlegroups.com, e955...@gmail.com

Not anything that is exactly similar. You have the option of either working with the Python commands module, which mirrors the way MEL works, or you can use the Python API which mirrors how the C++ API works. PyMel is its own separate 3rd party abstraction.

--
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.
Reply all
Reply to author
Forward
0 new messages