Python Variable

   1491   2   0
User Avatar
Member
169 posts
Joined: April 2014
Offline
I created a variable in a Python Sop called StartingPoint.

How can I use this variable in parameters in Sops down the pipe.

So I got to a Sop parameter, switch it to Python and type in what??

Done a lot of research online but found only info about doing calculations etc… Nothing about putting a variable you've created.

Thanks
Edited by firefly9000 - Nov. 29, 2016 19:49:11
Winter is coming!
User Avatar
Member
2539 posts
Joined: June 2008
Offline
The Python SOP is really just a one-shot code snippet that falls out of scope once it executes. So there is no way to to preserve a “global” variable. AFAIK. But you can use python to write a value to the detail attribute of the current geometry. This would be a likely place to store global variables for later processing down stream.
n = geo.addAttrib(hou.attribType.Global, "my_global", 100)

Check out the docs for more info.
http://www.sidefx.com/docs/houdini15.5/hom/hou/Attrib [sidefx.com]
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
When I want self-created Python variables that I am going to use in different paramters I use the “Python Source Editor” which is under the Windows tab at the very top.

It can be as simple as wanting it to be like a “global constant” such as “myvalue = 34” in which to use in any paramater or python expression elsewhere it's a simple matter of using “hou.session.myvalue”

I also sometimes define functions there in the python editor and reference it the same way like hou.session.myfunction().

Sometimes for various reasons I'll even put a channel reference in the pyton source editor like; my_reference = ch(“obj/node/theparamter”) and just use that; hou.session.my_reference
  • Quick Links