Jump to content

Access custom script in HDA


esan

Recommended Posts

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?

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

  • 7 months later...

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