Jump to content

Calling a function in a python Sop from an HDA button callback


defc0n1

Recommended Posts

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

Link to comment
Share on other sites

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

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.'?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 by Stalkerx777
  • Like 1
Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)?

Link to comment
Share on other sites

  • 2 years later...
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!

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...