Run script in python node on button push

   10425   10   3
User Avatar
Member
27 posts
Joined: Aug. 2018
Offline
Hello,

I have a HDA which has inside a geometry node with python node. This python node contains a script which reads a file, parses it and sets some attributes.
On HDA interface I have a button “Import File” which should start somehow python script inside a node described above.
The only way I found is to set off and then onn again a “bypass” flag: hou.node(“rig_dop_animation_driver/animation”).bypass(1);
But it doesn't work if HDA is locked. I need a way to run python script in a python node with locked HDA.
Is there a way to do it?

Thanks!
User Avatar
Member
8525 posts
Joined: July 2007
Online
normally your Python SOP should recook every time you change it's parametrs or it it's time dependent and time changes, so in theory there should be no need to recook

however there may be situations (though not adviseable) where you are reaching to HDA parameters directly from Python SOP code so it will not know to recook when those change or maybe there is another reason for it
in which case you may want to try call node.cook() with your Python SOP as node, however I'm a bit suspicious of the setup as Python SOP should cook in situations I mentioned
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
27 posts
Joined: Aug. 2018
Offline
In my case the only thing is changed is a file on the disk. It contains values for some attributes prepared by another application. It would be of'course perfect if houdini could somehow notice that file is changed and recook all relevant nodes. But the solution where I have to push a button to recook python node is acceptable.
I already tried “cook” method. It doesn't work (perhaps Houdini ‘thinks’ that nothing was changed an there is no need to recook)
But I found a solution and is is exactly your idea to reach to HDA parameter directly from Python SOP. It works.
I introduced an integer parameter to HDA interface. Python script in SOP node reads this parameter. And each time when I change this parameter in HDA interface, the script in PythonSOP is executed (or node is recooked). Works stable like a charm. But it still feels like a ‘hack’. It would be nice to have a method which executes script (recooks node) even if nothing is changed.
User Avatar
Member
8525 posts
Joined: July 2007
Online
try this
node.cook(force=True)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
27 posts
Joined: Aug. 2018
Offline
Thanks a lot. It does really work. It looks like that first time I did something wrong. Thanks.
User Avatar
Member
88 posts
Joined: Feb. 2021
Offline
you can just ad
hou.node('./').cook(force=True)
In the callback script
Edited by TangheStudent - Jan. 26, 2022 09:39:17
User Avatar
Member
385 posts
Joined: July 2018
Offline
is there a way to have a Save button as a parameter, execute a function on a simple python SOP? without an HDA
Edited by papsphilip - Aug. 10, 2022 11:25:21
User Avatar
Member
1 posts
Joined: Nov. 2021
Offline
I have the same issue. in houdni everything is fine.
but I neet to rebuild the hda to make the hda output the result every time.


unity 2019.4.39
houdini 19.0.657
User Avatar
Member
94 posts
Joined: Nov. 2017
Offline
I have more or less a similar problem. I want to call a function inside the python sop from the hda in order to start the python sop. The misery is that otherwise it wants to cook every time I load the scene which is a pain in the butt (if I don't put the parts into a function which start the other functions).

Can this be done? Call a script from the hda in the python sop?
User Avatar
Member
8525 posts
Joined: July 2007
Online
The Python SOP being executed when you load the scene is no mystery as long as it's in the cook path, since Python SOP executes every time it cooks
Think of Python SOP as Attributes Wrangle

What is your actual goal?
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2 posts
Joined: April 2020
Offline
I have a better ideal.
create a toggle named 'auto_run'

in python script:
def main():
    print(hou.ch('auto_run'))

if hou.ch('auto_run'):
    main()
you can do what ever you want in main function,
It will not excute main() even you modified the main function body.
It will only run and auto recook if you toggle the auto run as if it is not exist.
If you want to cook it as a single run, just toggle auto run, then toggle it again.
  • Quick Links