Accessing Python Node from Another Python Node

   2244   2   1
User Avatar
Member
2048 posts
Joined: Sept. 2015
Offline
Hello,

I'm trying to figure out how I can access code written in one python node like definitions and “variables” “declared”/“set” and access it from another python node.

This is more of a continuing exercise for me to see how much I can and cannot do with Python in Houdini.

The screenshot I'm attaching should be able to illustrate the principal I am trying to do.

I have tried many versions of this like using “import” and different wiring of the nodes as well but still am unable to make any reference and use code that is in one python node in another.

Any help is appreciated, thank you.

Attachments:
Example_A.jpg (257.6 KB)

User Avatar
Member
1913 posts
Joined: Nov. 2006
Offline
Python Objects/SOPs don't work that way. When they are cooked they execute the code like a script and don't store variables or anything like that.

The closest you're able to do is to evaluate the code parameter as a string and then exec it in your local namespace to have access to anything that might be set in there.

If you need shared data between objects you might want to look at storing things in either hou.session, the Python Source Editor (which dumps into hou.session) or external modules.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
2048 posts
Joined: Sept. 2015
Offline
Ok, thanks graham:

Good to know, now I can let that avenue go.

Actually, originaly I was using Python Source Editor but it was starting to get to the point where I had too much stored in one place.

So I was looking for a way to break things up into parts.

I was working with storing things in script *.py files and doing things like
“ from ‘scriptfile’ import * ”
for the Python Source Editor but it seems I can only import down into one level.

The “variables” stored in the script file were able to be accessed directly from the python node with the same,
“from ‘scriptfile’ import * ” notation,
but a function within the Python Source Editor that uses one of those “variables” as an argument when used in the python node doesn't seem to be able to access that variable.

It's like it can only be passed/referenced down one level. No “nesting” type behaviour seems to be allowed.

I think I am going to look into the HDK and play with some C++.

Thanks for your feedback.
  • Quick Links