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?
Access custom script in HDA
Started by esan, Jul 19 2012 03:39 PM
3 replies to this topic
#1
Posted 19 July 2012 - 03:39 PM
#2
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:
You can then do this:
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
Posted 20 July 2012 - 09:30 AM
graham, 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:
You can then do this:
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
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'.)
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
- Charles Darwin
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users










