How to get camera list in viewport data ( python)

   3999   4   2
User Avatar
Member
9 posts
Joined: May 2015
Offline
I need to get camera list in hip file.

I tried to this :
node.allSubChildren or toolutils.findAllChildNodesOfType


but, It is very slow because recursion.

I want to use data from ‘Scene View’ that has camera list.

How to use this data in python ??
Edited by JMoon - Nov. 6, 2018 00:57:41

Attachments:
cam_list.png (39.2 KB)

User Avatar
Member
12 posts
Joined: May 2017
Offline
The hou.NodeType class has a .instances() function which will return a tuple of all the nodes of that type in your scene.

To use that to get all the cameras you could do something like this:
cameras = hou.nodeType(hou.objNodeTypeCategory(),"cam").instances()
User Avatar
Member
9 posts
Joined: May 2015
Offline
Hello Leaf.
That's exactly what I wanted.
Thank you for your reply.
User Avatar
Member
8177 posts
Joined: Sept. 2011
Offline
If you want not just ‘cam’ cameras, but hda cameras such as vrcam and any custom cameras a studio might use, you can try ‘recursiveGlob’. It seems reasonably fast for how complex it sounds. The trick is to use a filter.

root = hou.node('/')
camera_nodes = root.recursiveGlob('*', hou.nodeTypeFilter.ObjCamera) # '*' is a pattern which matches the globbed node names
User Avatar
Member
9 posts
Joined: May 2015
Offline
Thank you, jsmack

That's a very nice tip !!!
Edited by JMoon - Nov. 7, 2018 00:14:21
  • Quick Links