Evaluate in Python from a path ?

   249   6   1
User Avatar
Member
552 posts
Joined: April 2014
Offline
I'm using Hscript within a Python Shell but I want to evaluate a parameter on the SOP within the Python Shell in Python. I'm at the node to which I want to evaluate a parameter but running `eval(“TX”)` for example gives an error ?
Houdini is Life Cereal, once you had a bowl you can't stop.
User Avatar
Member
18 posts
Joined: Sept. 2017
Offline
What is the error you are getting?

Also, I don't fully understand what you mean by “evaluate a parameter on the SOP within the Python Shell”? Could you upload an example scene?
User Avatar
Member
552 posts
Joined: April 2014
Offline
Suppose I'm at the following path
/obj/grid_object1/box1

I want to evaluate the `sizeX` parameter for the box. How can I do this at the path what I mentioned above ? If I type
at />>> eval(“tx”) I get the following error; name ‘tx’ is not defined ?
Houdini is Life Cereal, once you had a bowl you can't stop.
User Avatar
Staff
2762 posts
Joined: July 2005
Offline
you'll want to get the node as a python object:

>> mybox = hou.node('/obj/grid_object1/box1') # <— you can drag a node into the Python Shell to see this path

then you can evaluate the parameter

>> print mybox.parm('sizex').eval()
Michael Goldfarb | www.odforce.net
Senior Technical Director
SideFX
www.sidefx.com
User Avatar
Member
552 posts
Joined: April 2014
Offline
When doing %cd I get path to the sop. The prompt displayed is />>> which I assume is the path to the sop. Can I run eval() from this prompt on the current sop path ?
Houdini is Life Cereal, once you had a bowl you can't stop.
User Avatar
Member
18 posts
Joined: Sept. 2017
Offline
python doesn't understand where you are in the same way hscript does. As arctor said, you need to run eval() on the node as a python object.

The function my_node = hou.node(“/obj/path_to_node”) will return the node as a python object and store it as my_node. You can then call my_node.parm(“tx”).eval() to get the tx parameter value of this node. This is all in arctors post.
User Avatar
Member
147 posts
Joined: Dec. 2011
Offline
It's true that if you run the code in the shell, python won't know what node you're talking about without you passing it specifically. However, if you run code as a python expression on the node itself then you can access the parameter that called the function with hou.evaluatingParm(). Once you have that parameter you can backtrack to the node and get the ‘tx’ parameter you want.

node = hou.evaluatingParm().node()
parm = node.parm('tx')

Again this will not work in the shell, only when executing code on the node itself.
  • Quick Links