How to properly stack multiple OnCreated Python events?

   718   1   2
User Avatar
Member
113 posts
Joined: Aug. 2017
Offline
I downloaded an HDA which has an embedded OnCreatedscript that I didn't want to touch.
I then added my own external OnCreatedscript by creating a /scripts/lop/thatHDAfromtheweb_OnCreated.pyin order to add my own code. (more on it here [www.sidefx.com])
So I had two competing scripts. As a result, my script overrode the embedded one.

Luckily, I found help on Think Procedural Discord server where @probiner suggested trying this code in my external script as a workaround :
exec(kwargs["node"].type().definition().sections()["OnCreated"].contents())

It basically executes the embedded script from my external script.

And it works, but it feels a bit hacky. Is there a proper way to do this, or is this it?
User Avatar
Member
247 posts
Joined: May 2017
Offline
There is a method called 'createModuleFromSection' in the toolutils module which basically does the same as your code above. And as I know there is no other way to manage this and nothing wrong with it, just a placeholder for other code. Might be tricky if you are generating code within the events module, but still possible.

hou.HDAModule [www.sidefx.com]
  • Quick Links