Jump to content
ikoon

NodeTypeCategory (i.e. how to read X,Y from <hou.X for Y>)

Recommended Posts

tldr: I cannot work with this type of data <hou.NodeTypeCategory for Chop>  please could you post an example of the if statement?

I have to check, if the Network Editor is currently inside Sop, or inside Chopnet etc. My skills are not enough to make the if statement right. I tried to search, but everything failed.
So this is really wrong, just for example:

current_type = node.childTypeCategory()
compare_type = "<hou.NodeTypeCategory for Chop>"
if current_type == compare_type:
    print "I am inside Chopnet"

 

I made this working workaround, but if anybody has time, please could you fix the above statement?

current_label = node.childTypeCategory().label()
compare_label = "Motion FX"
if current_label == compare_label:
    print "I am inside Chopnet"

 

Share this post


Link to post
Share on other sites

Preamble:

>>> node = hou.node('/obj/geo1')

>>> node.childTypeCategory()
<hou.NodeTypeCategory for Sop>

>>> cat = node.childTypeCategory()

Ok.

The "wrong" snippet compares object to a string representation, they are different. It prints "<hou.NodeTypeCategory for Chop>" because of its __str__ or __repr__ method:

>>> cat.__str__()
'<hou.NodeTypeCategory for Sop>'
>>> cat.__repr__()
'<hou.NodeTypeCategory for Sop>'

>>> str(cat) == '<hou.NodeTypeCategory for Sop>'
True
>>> repr(cat) == '<hou.NodeTypeCategory for Sop>'
True

 

You can compare name (or label, like you did) with corresponding string. This is probably what most people will do:

>>> cat.name() == 'Sop'
True

 

You can compare Python objects directly, if you have one already or know how to make it. Here is couple of methods:

>>> hou.nodeTypeCategories()['Sop']
<hou.NodeTypeCategory for Sop>

>>> hou.sopNodeTypeCategory()
<hou.NodeTypeCategory for Sop>

>>> cat == hou.nodeTypeCategories()['Sop']
True

>>> cat == hou.sopNodeTypeCategory()
True
if node.childTypeCategory() == hou.chopNodeTypeCategory():
    # In ChopNet.
  • Like 1

Share this post


Link to post
Share on other sites

Oh! That's how it is, now I see it clear.

F1 you are my savior, thank you very very much. You really help me advance, thank you!!! Btw do you have a patreon?

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×