How to check if node is camera or light with python

   3315   6   1
User Avatar
Member
78 posts
Joined: May 2018
Offline
I feel like this is a stupid question, but I just can't seem to figure it out. How would I determine if a node is a special rendering node such as a light or a camera? Is there a property that gets set or something so that mantra picks up on this? How would I quickly access this information for filtering my node searches in Python?
Edited by Ashen - Nov. 20, 2019 14:10:27
User Avatar
Staff
3459 posts
Joined: July 2005
Offline
>>> node = hou.node('/obj/somenode')
>>> print node.type()
<hou.NodeType for Object cam>
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
8035 posts
Joined: Sept. 2011
Offline
goldfarb
>>> node = hou.node('/obj/somenode')
>>> print node.type()
<hou.NodeType for Object cam>

what if it's a camera hda where the type is not ‘cam’?
User Avatar
Staff
3459 posts
Joined: July 2005
Offline
you should find the type of node then based on that do something…
so if it's an HDA of type mySpecialCam then do something etc
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
8035 posts
Joined: Sept. 2011
Offline
That would require hard coding every camera type.

The closest way I can find is using recursive glob and a node filter. It's kind of ugly, but it seems to work.

obj = hou.node('/obj')
stereo_cam = obj.createNode('stereocamrig')
cam1 = obj.createNode('cam')
cam2 = obj.createNode('vrcam')
null1 = obj.createNode('null')
light1 = obj.createNode('hlight')
cam1 in cam1.parent().recursiveGlob(cam1.path(), hou.nodeTypeFilter.ObjCamera)
True
cam2 in cam2.parent().recursiveGlob(cam2.path(), hou.nodeTypeFilter.ObjCamera)
True
stereo_cam in stereo_cam.parent().recursiveGlob(stereo_cam.path(), hou.nodeTypeFilter.ObjCamera)
True
light1 in light1.parent().recursiveGlob(light1.path(), hou.nodeTypeFilter.ObjLight)
True
null1 in null1.parent().recursiveGlob(null1.path(), hou.nodeTypeFilter.ObjCamera)
False
User Avatar
Member
78 posts
Joined: May 2018
Offline
You hit the nail on the head jsmack. Somehow mantra knows what nodes are to be used as lights or cameras independent of their node type name. Clever hack with the nodeTypeFilter, though I imagine that it won't scale very nicely. Would be nice to have access to the data it is using to filter them under the hood. It feels like nodeType is missing a method for type class or something.
Edited by Ashen - Nov. 20, 2019 19:06:12
User Avatar
Member
78 posts
Joined: May 2018
Offline
Another issue is that if I have a node and want to find its filterType I would have to iterate over all filterTypes until I find one that matches. Also since there is some overlap between filterTypes, I would have to be careful of the order I check them in.
Edited by Ashen - Nov. 20, 2019 19:47:16
  • Quick Links