defc0n1 Posted July 22, 2017 Share Posted July 22, 2017 Hey guys I have an HDA with 2 python SOPs inside. I need a button on the HDA that would trigger a function in one of the python SOPs. I looked at how callback scripts work but it was too confusing. Appreciate it if someone could help me out. Thanks! Cheers defc0n1 Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted July 22, 2017 Share Posted July 22, 2017 (edited) Python SOPs shouldn't contain code which intended to be called outside, Houdini cooks SOPs when it's needed. Define your functions in HDA's PythonModule and call them from there, even from within Python SOPs inside, if you wish so. Edited July 22, 2017 by Stalkerx777 Quote Link to comment Share on other sites More sharing options...
defc0n1 Posted July 22, 2017 Author Share Posted July 22, 2017 7 minutes ago, Stalkerx777 said: Python SOPs shouldn't contain code which intended to be called outside, Houdini cooks SOPs when it's needed. Define your functions in HDA's PythonModule and call them from there, even from within Python SOPs inside, if you wish so. Right. I'll need to fix that. Could you explain that last part - '...even from within Python SOPs inside, if you wish so.'? Quote Link to comment Share on other sites More sharing options...
defc0n1 Posted July 22, 2017 Author Share Posted July 22, 2017 8 minutes ago, Stalkerx777 said: Python SOPs shouldn't contain code which intended to be called outside, Houdini cooks SOPs when it's needed. Define your functions in HDA's PythonModule and call them from there, even from within Python SOPs inside, if you wish so. Oh wait does it mean I can call a function in an internal Python SOP from within the python module in the HDA? Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted July 22, 2017 Share Posted July 22, 2017 (edited) 24 minutes ago, defc0n1 said: Oh wait does it mean I can call a function in an internal Python SOP from within the python module in the HDA? Exactly. This is, in general, a good practice to define all your shared Python code in a top level HDA, and use it anywhere you need, like that: module = hou.nodeType("Sop/MyHDA").hdaModule() module.my_func() Edited July 22, 2017 by Stalkerx777 1 Quote Link to comment Share on other sites More sharing options...
defc0n1 Posted July 22, 2017 Author Share Posted July 22, 2017 8 minutes ago, Stalkerx777 said: Exactly. This is, in general, a good practice to define all your shared Python code in a top level HDA, and use it anywhere you need, like that: module = hou.nodeType("Sop/MyHDA").hdaModule() module.my_func() Thank you!!! Quote Link to comment Share on other sites More sharing options...
defc0n1 Posted July 23, 2017 Author Share Posted July 23, 2017 He Alex..sorry I hit a wall again. My internal python node adds detail attributes so when I define the same code within the HDA python module, it says that the geometry is read-only. I read somewhere that you can't modify geometry from within an HDA's python module? My function examines a binary file and adds some attributes based on the parameters it finds in the file. Problem is, the file is HUGE and I don't want it to cook every time I change the file to be analysed. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted July 24, 2017 Share Posted July 24, 2017 Just pass you geometry as an argument to your function. In HDA: def modify_geo(geo): geo.addAttribute(...) return geo In Python SOP: module = hou.nodeType("Sop/MyHDA").hdaModule() geo = module.modify_geo(geo) Quote Link to comment Share on other sites More sharing options...
defc0n1 Posted July 31, 2017 Author Share Posted July 31, 2017 On 24/07/2017 at 3:12 AM, Stalkerx777 said: Just pass you geometry as an argument to your function. In HDA: def modify_geo(geo): geo.addAttribute(...) return geo In Python SOP: module = hou.nodeType("Sop/MyHDA").hdaModule() geo = module.modify_geo(geo) Right....how do I call this from using callback script? Do I just do hou.pwd().hdaModule().modify_geo(geo)? Quote Link to comment Share on other sites More sharing options...
defc0n1 Posted July 31, 2017 Author Share Posted July 31, 2017 6 minutes ago, defc0n1 said: Right....how do I call this from using callback script? Do I just do hou.pwd().hdaModule().modify_geo(geo)? Never mind. Stupid question. Quote Link to comment Share on other sites More sharing options...
zeemzoet Posted June 21, 2020 Share Posted June 21, 2020 On 7/31/2017 at 10:04 PM, defc0n1 said: Right....how do I call this from using callback script? Do I just do hou.pwd().hdaModule().modify_geo(geo)? Hi there! I'm trying to do something similar, but I'm still trying to get my head around it all. You said yourself it was a stupid question, but I'm stuck myself. Any chance you (or anyone else) could clarify how to call the function in the python sop inside the hda? Many many thanks! Quote Link to comment Share on other sites More sharing options...
sant0s81 Posted June 22, 2020 Share Posted June 22, 2020 Dont find the post where I found that, so credits go to one of the Python masters here: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.