Jump to content
tagosaku

Can we execute python def by another node remotely?

Recommended Posts

there are 2 nodes, and can we remotely  execute a python script by another node, especially def too? 

For instance, there is a python_target null node. If I click its execute button, it writes C in result as I expect. Then I want to do same thing by a code of another python_remote_control null node. 

After succeeding controlling remotely, I also like to execute setA() remotely, too. 

Is that possible?

image.thumb.png.b046884f0b2b6938f153eff86e8686e4.png

 

Share this post


Link to post
Share on other sites

I know I could write script directly in python_remote_control node

import hou
a = hou.node('/obj/pipeline/python_target')
a.parm('result').set('C')

but I would like to know how to control/execute the code of 'python_target' node indirectly

Share this post


Link to post
Share on other sites

Nothing is impossible, but this is not a common way of working with Python in Houdini. For geometry manipulation use Python SOP, for sharing your Python code, put it a module, hou.session, or into HDA's Python module. See the docs

 

To achieve exactly what you want:

In your python_remote_control:

code = hou.node('../target_python').evalParm('code')

exec compile(code, "inline", "exec"), globals(), locals()

setA()
setB()

 

  • Like 1

Share this post


Link to post
Share on other sites
code = hou.node('../target_python').evalParm('code')

exec (compile(code, "inline", "exec"), globals(), locals())

setA()
setB()

After adding an extra bracket, it worked for a test code now. From now I try to apply it for actual scripts. Thank you, Alex, R !!

Share this post


Link to post
Share on other sites
Posted (edited)

I am using  kwargs["node"] or hou.node('.') in order to point out self node. When executing from 'target_python' node, it makes sense to be kwargs["node"] = target_pyhon.

However, when executing from python_remote_control node, kwargs["node"] becomes 'python_remote_control node' and code does not work anymore. 

Do I need to write 2 code versions? 

 

In general, I guess python_remote_control node executes 'target_python's code as own self code. Then the code looks up not 'target_python''s parms  but python_remote_control node's parameters ?!?

Edited by tagosaku

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×