import maya.cmds as cmd import pymel.core as pm list = cmd.ls(sl=True) for obj in list: obj = pm.PyNode(obj) |
print pm.hasAttr(obj,'tx') |
--
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/0abb0814-ff47-42a9-9464-5ce2f856dbee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
hasAttr will check only for existing attribute.
import maya.cmds as cmd
import pymel.core as pm
list = cmd.ls(sl=True)
for obj in list:
obj = pm.PyNode(obj)
print pm.hasAttr(obj,'tx')
This will work and what is getShape ?, is it a function ? or is it attribute which is existed in selected object ?
On Tue, Jun 17, 2014 at 3:08 PM, Brian Eyre <brian...@googlemail.com> wrote:
Hi,
I'm trying to add a line that error checks for whether the getShape() method exists for selected objects, by using hasAttr, but it keeps returning false even when getShape() exists for the obj:
import maya.cmds as cmd
import pymel.core as pm
list = cmd.ls(sl=True)
for obj in list:
obj = pm.PyNode(obj)
print pm.hasAttr(obj,'getShape')
Any ideas??
--
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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0abb0814-ff47-42a9-9464-5ce2f856dbee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
----:: Kurian ::--
import maya.cmds as cmd import pymel.core as pm list = cmd.ls(sl=True) for obj in list: obj = pm.PyNode(obj) |
if obj.getShape(): print obj.getShape() |
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/1637e11d-8553-4b2d-a79a-43ae0c0cfc27%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0abb0814-ff47-42a9-9464-5ce2f856dbee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
----:: Kurian ::--
--
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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1637e11d-8553-4b2d-a79a-43ae0c0cfc27%40googlegroups.com.
----:: Kurian ::--
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dca48f87-4fa9-4f61-ab57-0182c9d6f16a%40googlegroups.com.To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
import maya.cmds as cmd import pymel.core as pm list = cmd.ls(sl=True) for obj in list: obj = pm.PyNode(obj) |
print hasattr(obj,'getShape') |
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1637e11d-8553-4b2d-a79a-43ae0c0cfc27%40googlegroups.com.
----:: Kurian ::--
--
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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dca48f87-4fa9-4f61-ab57-0182c9d6f16a%40googlegroups.com.
----:: Kurian ::--
import maya.cmds as cmd import pymel.core as pm list = cmd.ls(sl=True) for obj in list: obj = pm.PyNode(obj) |
print hasattr(obj,'getShape') |
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3096bcdd-5f8e-44af-8f2b-fc6f396c4e91%40googlegroups.com.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/dca48f87-4fa9-4f61-ab57-0182c9d6f16a%40googlegroups.com.
----:: Kurian ::--
--
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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3096bcdd-5f8e-44af-8f2b-fc6f396c4e91%40googlegroups.com.
----:: Kurian ::--
Sorry if this is late info but, the Maya hasAttr is meant to check for the existence of attributes on an object. But these are not functions as everything in Maya command API are string references and you use function calls only to perform certain operations on string references
Python has a similar hasattr which tells you if a python object has a certain member attribute
In your case, neither of these applied, as what you were after was just to try and call the PyMel getShape and handle the specific AttributeError
Hope that was clear enough? Let me know if you need more details on that
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/1627dff8-1c2b-4dd9-974d-ce6512165ce1%40googlegroups.com.