esan Posted July 19, 2012 Share Posted July 19, 2012 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? Quote Link to comment Share on other sites More sharing options...
graham Posted July 19, 2012 Share Posted July 19, 2012 (edited) 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 July 19, 2012 by graham Quote Link to comment Share on other sites More sharing options...
esan Posted July 20, 2012 Author Share Posted July 20, 2012 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. Quote Link to comment Share on other sites More sharing options...
kgoossens Posted February 21, 2013 Share Posted February 21, 2013 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'.) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.