How to know if a node is camera (include cam HDA) ?

   2441   7   3
User Avatar
Member
620 posts
Joined: Nov. 2013
Offline
Hi,

I created an HDA myCam. And need to do something in python for Object/cam and myCam.
Though I can test if the type.name() is “myCam”. I want a more general method to know if the node belongs to camera.
Are there any way to know if a node is a camera (include cam HDA)?

Thanks!
User Avatar
Member
806 posts
Joined: Oct. 2016
Offline
Hi,

have you tried reading the documentation? Node type for “cam” is … wait for it … “cam” :-)

Documentation says “node.type()” gives you the node type, so in Python you would do something like
hou.node("/obj/myCam").type()
, which would return “cam”. You could traverse all your “/obj” nodes and check for each node's type whether it is “cam”.


Marc
---
Out of here. Being called a dick after having supported Houdini users for years is over my paygrade.
I will work for money, but NOT for "you have to provide people with free products" Indie-artists.
Good bye.
https://www.marc-albrecht.de [www.marc-albrecht.de]
User Avatar
Member
251 posts
Joined: July 2013
Offline
malbrecht
Hi,

have you tried reading the documentation? Node type for “cam” is … wait for it … “cam” :-)

Documentation says “node.type()” gives you the node type, so in Python you would do something like
hou.node("/obj/myCam").type()
, which would return “cam”. You could traverse all your “/obj” nodes and check for each node's type whether it is “cam”.


Marc

…type().name() would be the thing that returns the actual name string, important since you want to be able to compare it to the string “cam”
More code, less clicks.
User Avatar
Member
7737 posts
Joined: Sept. 2011
Offline
Jonathan de Blok
malbrecht
Hi,

have you tried reading the documentation? Node type for “cam” is … wait for it … “cam” :-)

Documentation says “node.type()” gives you the node type, so in Python you would do something like
hou.node("/obj/myCam").type()
, which would return “cam”. You could traverse all your “/obj” nodes and check for each node's type whether it is “cam”.


Marc

…type().name() would be the thing that returns the actual name string, important since you want to be able to compare it to the string “cam”

That only works for the houdini cam. The OP is asking how to tell if any node is a camera class, not type. I'm not sure if there is a way other than recursive glob, which isn't very friendly for simple masking. I've resorted to hard coded lists of type names for this purpose.
User Avatar
Member
30 posts
Joined:
Offline
hey all,

as a followup to this, i trawled through the HTOA properties source and discovered they were using the node.type().definition().extraInfo() thingo - it has a “subtype=cam” entry for camera derived types.

It certainly works for my own custom camera OTLs.

i have no idea whether this is a formal houdini thing that you can 100% rely upon, but as hou has no concept of type def subclasses, it's the closest that i've ever seen (short of globbing parms and saying “yep, this looks like a camera… ish”)

hope this helps.

cheers,
chrisg
User Avatar
Member
7737 posts
Joined: Sept. 2011
Offline
doctorbob
It certainly works for my own custom camera OTLs.

It doesn't work on non-otl cameras though, since their types don't have a ‘definition’, such as the built in ‘cam’ type and lopimportcamera type.

Using
mycam in mycam.parent().recursiveGlob(mycam.name(), filter=hou.nodeTypeFilter.ObjCamera)
has been the only sure fire way I've found. There's got to be something simpler.
User Avatar
Member
30 posts
Joined:
Offline
well, that's a super useful snippet. thanks!

cheers,
chrisg
User Avatar
Member
122 posts
Joined: June 2019
Offline
Hi all!

Looks like these classes are not exposed to HOM. As a workaround you can use inlinecpp to check if OBJ node is a camera. Though you need Visual Studio installed (or Xcode on OSX) to use it. So no simple way afaik

Try to put this in session module:
import inlinecpp

utils = inlinecpp.createLibrary("utils", 
    includes="#include <OBJ/OBJ_Node.h>",
    function_sources=["""
bool isCamera(OBJ_Node* node)
{
     return node->castToOBJCamera() != NULL;
}
"""])

Then you can check OBJ nodes like this
node = hou.node("obj/cam1/")
geo_node = hou.node("obj/geo1/")
print hou.session.utils.isCamera(node) # True
print hou.session.utils.isCamera(geo_node) # False

That would work with builtin and hda cameras
Edited by elovikov - Aug. 18, 2020 18:40:14
  • Quick Links