I’m trying to determine if an object is of class “light”.
If I do nodeType(theObj) I get the class of the object; ie VrayLightMesh. How do I get the superclass of the object; ie “light” ?
In maxscript I would simply do superclassof theObj, what is the pythonic approach to do this?
Thanks!
p.
I am not familiar with VrayLightMesh. However, if the node type derives from “light”, you can do the following:
cmds.objectType(theObj, isa='light')
This will return True or False.
from maya import cmds
nType = "ambientLight"
inherited = cmds.nodeType( nType, inherited=True, isTypeName=True )
for i in inherited:
dependencies = cmds.listNodeTypes( i ) or []
if nType in dependencies:
print i
seems to be a long way round, others might have a better idea
*edit
just tested it on a few more node types, doesn’t seem to work on all types, but maybe it will suit your needs
nodeType -i will list all the types that a give object inherits from; ls -type will filter a list on nodeTypes, including the abstract inherited ones:
>>> cmds.createNode('ambientLight')
#u'ambientLightShape1'
>>> cmds.nodeType('ambientLightShape1', i=True)
#[u'containerBase', u'entity', u'dagNode', u'shape', u'light', u'renderLight', u'ambientLight']
>>> cmds.ls('ambientLightShape1', type = 'light')
#[u'ambientLightShape1']
>>> cmds.ls('ambientLightShape1', type = 'transform')
#[]
So you could do
if 'light' in nodeType(object, i=True):....
on one object or
only_lights = cmds.ls(*list_of_things, type = 'light')
to filter a list of candidates and return only lights
Thanks for the suggestions guys, I’ll give them go!
Cheers
p.
Theodox, is there a reason you unpack your list when calling ls, or is just a personal preference?
I do that habitually in functions, so I can call lists, tuples or singles as needed; it just carries over in this case