compare to know if i am dealing with ObjNode or SopNode

   2795   6   2
User Avatar
Member
3 posts
Joined: Nov. 2014
Offline
hello esteemed members of houdini,
i am trying to make a comparison to know if a node input is of type ObjNode or SopNode.

Here is my shell test code:


>>> a=hou.node('/obj/box_object1')
>>> b=hou.node('/obj/box_object1/box1')
>>> a.type()
<hou.NodeType for Object geo>
>>> b.type()
<hou.SopNodeType for Sop box>

here is my function code:




def modify_my_geometry(inputnode):
if (inputnode.type()==hou.SopNodeType):
print(“I can now access the inputnode.geometry() to modify it”)
else
print(“there is no geometry object here for me to modify”)


As you can see, i am trying to figure out if a geometry is present for me to add primitives ,points etc to it or modify existing.
Can you help me ?
yours faithfully,
Jeeten
User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
You can get child nodes using:
node.children()
User Avatar
Member
3 posts
Joined: Nov. 2014
Offline
Thank you for your reply,
Unfortunately i am in fact looking for a way to make comparison of the types of nodes and get true false answers from an if statement.
if (nodetype==sopnode):
yours faithfully,
Jeeten
User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
Need some thing like this:

import soptoolutils
from soptoolutils import hou.sopNodeTypeCategory()

if cwd.childTypeCategory() == hou.sopNodeTypeCategory():
User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
check soptoolutils.py

you can find it here:
$HFS/houdini/python2.7libs/soptoolutils.py
User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
You can write like this:

context = activepane.pwd().childTypeCategory()
def modify_my_geometry():
if context == hou.sopNodeTypeCategory() \
and activepane.isCreateInContext():

{
do this
}

else:
{
do nothing
}
User Avatar
Member
463 posts
Joined: Aug. 2014
Offline
yourNode = hou.node('/obj/geo/null1')
You can use Python's isinstance() built-in function:
isinstance(yourNode, hou.SopNode)
The above will return true if yourNode is an instance of a SopNode class, and false if it's not.

Type comparison will also work, although it ignores inheritance (shouldn't matter in this particular case):
type(yourNode) == hou.SopNode
  • Quick Links