Jump to content

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


ikoon

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"

 

Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...