jonp Posted January 22, 2017 Share Posted January 22, 2017 Greetings, I have a scripted menu parameter that is built from a filtered, sometimes extremely long list of files. When I select a node with this parameter, the first time I do it there is a very long pause where I cannot do anything in the UI. Subsequent access is faster as I'm caching the results of the first lookup. HOWEVER, the first pause is annoying enough. It would be great if there was a way to build the menu contents as a background process somehow and just have the menu script read from a stored list somewhere that is continuously updated (with a caveat message in the menu saying that the list is still being built). Any ideas on how to elegantly do this? Cheers, Jon Quote Link to comment Share on other sites More sharing options...
f1480187 Posted January 22, 2017 Share Posted January 22, 2017 Try threading: import threading node = kwargs['node'] if not node.cachedUserData('menu'): menu = ['', 'Loading items...\nReturn in 10 seconds...'] node.setCachedUserData('menu', menu) def fetch_menu(): # Simulate long operation. import time time.sleep(10) menu = ['item1', 'Label 1', 'item2', 'Label 2'] try: node.setCachedUserData('menu', menu) except hou.ObjectWasDeleted: pass t = threading.Thread(target=fetch_menu) t.start() return node.cachedUserData('menu') To reset, just delete node and undo. To update menu items automatically, add this under try statement: parm = kwargs['parm'] group = node.parmTemplateGroup() template = parm.parmTemplate() template.setMenuItems(menu[0::2]) template.setMenuLabels(menu[1::2]) group.replace(parm.name(), template) node.setParmTemplateGroup(group) slow_menu.hipnc 1 Quote Link to comment Share on other sites More sharing options...
jonp Posted January 22, 2017 Author Share Posted January 22, 2017 (edited) Great tip, thanks! I didn't know if Houdini would lock up anyways using threading. Fortunately it does not! Edited January 22, 2017 by jonp 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.