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!
Run script in python node on button push
10425 10 3- RadikSalakhov
- Member
- 27 posts
- Joined: Aug. 2018
- Offline
- tamte
- 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
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
FX Supervisor
Method Studios, NY
- RadikSalakhov
- 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.
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.
- tamte
- Member
- 8525 posts
- Joined: July 2007
- Online
- RadikSalakhov
- Member
- 27 posts
- Joined: Aug. 2018
- Offline
- TangheStudent
- Member
- 88 posts
- Joined: Feb. 2021
- Offline
- papsphilip
- Member
- 385 posts
- Joined: July 2018
- Offline
- fatlinliuxiaolin
- Member
- 1 posts
- Joined: Nov. 2021
- Offline
- Tom Mangold
- 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?
Can this be done? Call a script from the hda in the python sop?
- tamte
- Member
- 8525 posts
- Joined: July 2007
- Online
- blame4
- Member
- 2 posts
- Joined: April 2020
- Offline
I have a better ideal.
create a toggle named 'auto_run'
in python script:
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.
create a toggle named 'auto_run'
in python script:
def main(): print(hou.ch('auto_run')) if hou.ch('auto_run'): main()
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