gweiss Posted September 3, 2017 Share Posted September 3, 2017 Hi, learning python, I'm trying to do a simple test of creating a custom shelf tool that calls a function from a file to create a sphere I copy the create sphere shelf button script: import toolutils import soptoolutils rad = 0.5 kwargs['bbox'] = hou.BoundingBox(-rad, -rad, -rad, rad, rad, rad) sphere = soptoolutils.genericTool(kwargs, 'sphere') sphere.parm("type").set("polymesh") sphere.parm("radx").set(rad) sphere.parm("rady").set(rad) sphere.parm("radz").set(rad) I save a .py file with a new function and paste the script with a small change of - rad = 1 so I have a saved file called spherebig.py that looks like that import hou import toolutils import soptoolutils def createBigSphere(): rad = 1 kwargs['bbox'] = hou.BoundingBox(-rad, -rad, -rad, rad, rad, rad) sphere = soptoolutils.genericTool(kwargs, 'sphere') sphere.parm("type").set("polymesh") sphere.parm("radx").set(rad) sphere.parm("rady").set(rad) sphere.parm("radz").set(rad) in my new shelf tool I enter this on the script tab: import spherebig spherebig.createBigSphere() and when I press the button I get this error: NameError: global name 'kwargs' is not defined am I doing something wrong or is there a different way to create objects this way? Thanks gweiss Quote Link to comment Share on other sites More sharing options...
Atom Posted September 3, 2017 Share Posted September 3, 2017 Well, you have not passed in kwargs. I don't know this for certain, but when a button script is run by Houdini it is probably passing that in, behind the scenes. (i.e. tool shelf code is running inside of some sandbox that has been given kwargs). When you externalize that process you now have to become the provider of kwargs. Maybe read up a bit on python kwargs? 1 Quote Link to comment Share on other sites More sharing options...
f1480187 Posted September 3, 2017 Share Posted September 3, 2017 Add an argument to the function. It can be any name, use kwargs as convention: def createBigSphere(kwargs): pass Pass the kwargs when call it from shelf. import spherebig spherebig.createBigSphere(kwargs) kwargs is a dictionary populated with useful contextual stuff and available in most places where you use Python in Houdini. Contents are varying, so I usually print kwargs to see what's available to use. Shelf script kwargs contain details about how the user activated the script. I think Houdini kwargs is different from common Python **kwargs syntax and idiom, but they still share properties. Quote Link to comment Share on other sites More sharing options...
gweiss Posted September 3, 2017 Author Share Posted September 3, 2017 Thanks so much Atom and f1480187 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.