LaidlawFX Posted July 20, 2013 Share Posted July 20, 2013 Hello, Trying to figure out how to list directories in a string submenu, such as, a parameter drop down list(like a group list), but on windows. Say I want to list C:\Users\ so each user shows up in the menu. This help doc list how a submenu works; The python command works, but the hscript version doesn't work for some fun reason. http://www.sidefx.com/docs/houdini12.5/ref/windows/optype#menu_tab Also was trying to get uls -d as my source to fill the list but failing at that too, not sure if it's a windows thing. http://www.sidefx.com/docs/houdini12.5/commands/uls If anyone can help that be great, I would prefer hscript, but python works, too. Thanks -Ben Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted July 20, 2013 Share Posted July 20, 2013 (edited) Something like this should theoretically return all directories in specified path: def MakeList(path): import os dirList = os.listdir(path) dirs = [] for dirName in dirList: fullPath = os.path.normpath(os.path.join(path, dirName)) if os.path.isdir(fullPath): dirs += [fullPath, dirName] return dirs return MakeList("C:\Users") It works in python shell, but half-works in menu. When I return it, the listmenu is not fully populated with positions from python list. EDIT: It looks that it always populate menu with only half of the positions that python finds. For example. If I list my "C:\Program Files" where I have 38 items, python finds them correctly but Houdini will create list only from 19 elements from this list. So for my "C:\Users", where I have 6 dirs (with all hidden, protected ones) it will create menu of 3 positions. It is not a python problem because when you print list you will see all directories in the list, so must be a bug in Houdini or maybe I'm doing something wrong. Edited July 20, 2013 by mantragora Quote Link to comment Share on other sites More sharing options...
graham Posted July 20, 2013 Share Posted July 20, 2013 Python menus require your values in token/value pairs where the first element is the actual value and the second is the display string. When doing something like this you need to add each element twice (one for the token and one for the value). Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted July 20, 2013 Share Posted July 20, 2013 (edited) Python menus require your values in token/value pairs where the first element is the actual value and the second is the display string. When doing something like this you need to add each element twice (one for the token and one for the value). I have been all night on legs. It's 6.00 AM now. My eyes are not what they use to be when it was 20.00 PM and I just missed the part about pairs EDIT: Fixed the code. Edited July 20, 2013 by mantragora Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted July 21, 2013 Author Share Posted July 21, 2013 Awesome! works like a charm Thanks mantragora heroic late night effort, and thanks graham as always. -Ben Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted July 29, 2013 Author Share Posted July 29, 2013 Hey I get a python error if the directory doesn't exist yet? Is there away to capture/prevent that python error from being thrown to windows? Traceback (most recent call last): File "<stdin>", line 13, in expression File "<stdin>", line 4, in MakeList WindowsError: (3, 'The system cannot find the path specified', 'C:/Directory/Path/*.*') I was thinking of tossing a default path in there if this path does not exist... but there is probably a smarter way. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted July 29, 2013 Share Posted July 29, 2013 def MakeList(path): import os dirList = os.listdir(path) dirs = [] for dirName in dirList: fullPath = os.path.normpath(os.path.join(path, dirName)) if os.path.isdir(fullPath): dirs += [fullPath, dirName] return dirs try: return MakeList("C:\ShitHappens") except WindowsError: return ["WrongPath", "WrongPath"] Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted July 29, 2013 Share Posted July 29, 2013 (edited) You can also add to "except" part hou.ui.displayMessage("Path not found", severity=hou.severityType.Error) before "return", but I get multiple reports then on my system, so it can be a little annoying Edited July 29, 2013 by mantragora Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted July 29, 2013 Author Share Posted July 29, 2013 I like the return of the Wrong Path concept it seems to be working pretty good. The error messaging, or display messaging, was def annoying and I think it was making stuff shit on the farm... Thank you again wise python master, for saving my ass once more. 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.