Graham Thompson


About Me

Not Specified


Recent Forum Posts

Python If statement "or" doesn't work as expected April 15, 2021, 8:57 p.m.

The issue is with how Python interprets your conditional statement. It will evaluate it as: if 'shorts' or ('asdasfsdf' in nameAttr). So "shorts" is always True so it always prints. Without using operators which support intersection if you want to check for multiple values in the attribute vlaue you'll need to do something like: if 'shorts' in nameAttr or 'asdfasdf' in nameAttr: ...

How to add variables with python to the variable window? March 10, 2021, 12:26 p.m.

Your issue is that hou.putenv() is only creating local variables. Only global variables show up in the Aliases and Variables window and are saved in the file. Unfortunately hou.putenv() still doesn't provide a way to create global variables so you're forced to rely on hou.hscript() calls using 'set -g' to do this via Python:
hou.hscript("set -g PROJECT = {}".format(project))

Better way for checking a nodes type in python March 4, 2021, 2:27 p.m.

Technically the best way is to explicitly test against actual node types constructed with the operator table and name:

node = hou.node('/obj/geo1')
expected_type = hou.nodeType(hou.objNodeTypeCategory(), "geo")

if node.type() == expected_type:

You could also get the type from the node type category object:
category = hou.objNodeTypeCategory()

node_type = category.nodeTypes()["geo"]
node_type = category.nodeType("geo")