Jump to content

Can we execute python def by another node remotely?


tagosaku

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

 

Link to comment
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

Link to comment
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
Link to comment
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 !!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...