Jump to content


Access custom script in HDA


  • Please log in to reply
3 replies to this topic

#1 esan

esan

    Peon

  • Members
  • Pip
  • 2 posts
  • Joined: 19-July 12
  • Location:glendale CA
  • Name:esan mandal

Posted 19 July 2012 - 03:39 PM

I am trying to embed python modules in OTLs so that they get baked in to the OTL and is easier to distribute. However, I am unable to figure out how to execute that embedded python code form buttons or menus in the OTL. I can get the script in the PythonModule section of the OTL to work but if I import a 'Custom Script' through the 'Operator Type Properties' window then I am unable to figure out the right python syntax to access it.

If the python function is in the PythonModule then I can do the following in the menu button to execute it:

node.hdaModule().somePythonFunction(node)

What is the correct way of accessing the same function if it is in a 'Custom Script' section?

#2 graham

graham

    Houdini Master

  • Moderator
  • 666 posts
  • Joined: 13-September 06
  • Location:Santa Monica, CA
  • Name:Graham Thompson

Posted 19 July 2012 - 03:52 PM

If you have code in additional sections you need to convert those sections to modules in your PythonModule using the toolutils module.

For example, if you had a function foo() in an extra scripts section called "AdditionalCode", you would do this in your main PythonModule:
import toolutils
mymodule = toolutils.createModuleFromSection("mymodule", kwargs['type'], "AdditionalCode")

You can then do this:
node.hm().mymodule.foo()

Edited by graham, 19 July 2012 - 03:53 PM.

I write python and break things.

#3 esan

esan

    Peon

  • Members
  • Pip
  • 2 posts
  • Joined: 19-July 12
  • Location:glendale CA
  • Name:esan mandal

Posted 20 July 2012 - 09:30 AM

View Postgraham, on 19 July 2012 - 03:52 PM, said:

If you have code in additional sections you need to convert those sections to modules in your PythonModule using the toolutils module.

For example, if you had a function foo() in an extra scripts section called "AdditionalCode", you would do this in your main PythonModule:
import toolutils
mymodule = toolutils.createModuleFromSection("mymodule", kwargs['type'], "AdditionalCode")

You can then do this:
node.hm().mymodule.foo()


Brilliant!
Thanks - that works perfectly.

#4 kgoossens

kgoossens

    Initiate

  • Members
  • PipPip
  • 198 posts
  • Joined: 04-May 06
  • Location:Belgium, Antwerp
  • Name:Kim Goossens

Posted 21 February 2013 - 11:38 AM

Is it possible to access code of additional sections within an HDA "Menu script"?
I've tried to do this but I get a KeyError:('type'.)
“It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change.”

- Charles Darwin




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users