CinnamonMetal Posted October 2, 2017 Share Posted October 2, 2017 (edited) Hi, I'm a newbie at understanding scripting within Houdini so I hope all will understand. (Python) nodeName = hou.ui.readInput("what do you want",buttons=('OK',"Cancel"),default_choice=0,title="Name the sphere",close_choice=1) print(nodeName) if not nodeName[0] or nodeName[1] !="": intro = hou.node("/obj").createNode("geo","geometryA") superGeo = intro.createNode("sphere",nodeName[1]) superGeo.setParms({"radx":2.3,"radz":4.2,"type":"bezier","rows":54}) else: while nodeName[0] == "": print("you must supply a valid node name") get__input() I'm getting an invalid node name error when the user clicks on the OK button with an empty string rather then strictly the print statement ? Edited October 2, 2017 by CinnamonMetal Quote Link to comment Share on other sites More sharing options...
f1480187 Posted October 2, 2017 Share Posted October 2, 2017 Like this? while True: # Compute some result. result = stuff() if result: # Correct result branch. break # Incorrect result branch. ans = hou.ui.displayMessage( 'Some error text explaining situation.', buttons=('Retry', 'Cancel'), close_choice=1, severity=hou.severityType.Error ) if ans == 1: # User gave up. break 1 Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted October 2, 2017 Author Share Posted October 2, 2017 (edited) I got it, thanks @f1480187 Edited October 2, 2017 by CinnamonMetal Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted October 2, 2017 Author Share Posted October 2, 2017 nodeName = hou.ui.readInput("what do you want",buttons=('OK',"Cancel"),default_choice=0,title="Name the sphere",close_choice=1) if not nodeName[0] or nodeName[1] !="": intro = hou.node("/obj").createNode("geo","geometryA") superGeo = intro.createNode("sphere",nodeName[1]) superGeo.setParms({"radx":2.3,"radz":4.2,"type":"bezier","rows":54}) else: while not nodeName[0] == "": print("you must supply a valid node name") break No matter what I try for the while loop. When the user clicks "OK" I get a invalid node error instead of "you must supply a valid name" ? Quote Link to comment Share on other sites More sharing options...
f1480187 Posted October 2, 2017 Share Posted October 2, 2017 (edited) if not nodeName[0] or nodeName[1] !="": True if user pressed OK even if input is empty and also True if user typed something and then decided to Cancel. Try something more strict, like: if nodeName[0] == 0 and nodeName[1] != "": Edited October 2, 2017 by f1480187 1 Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted October 3, 2017 Author Share Posted October 3, 2017 nodeName = hou.ui.readInput("what do you want",buttons=('OK',"Cancel"),default_choice=0,title="Name the sphere",close_choice=1) if not nodeName[0] or nodeName[1] !="": intro = hou.node("/obj").createNode("geo","geometryA") superGeo = intro.createNode("sphere",nodeName[1]) superGeo.setParms({"radx":2.3,"radz":4.2,"type":"bezier","rows":54}) else: if nodeName[0] == 0 and nodeName[1] !="": print("you must supply a valid node name") I tried most combinations except; nodeName[0] == 0 which I was hoping would solve this. Except before when clicking `cancel` the print statement happened; the print statement isn't happened when clicking cancel and when clicking `ok` I get the same error; invalid node type ? Quote Link to comment Share on other sites More sharing options...
f1480187 Posted October 3, 2017 Share Posted October 3, 2017 You replaced wrong line. Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted October 3, 2017 Author Share Posted October 3, 2017 (edited) Thank you, that solved it. Edited October 3, 2017 by CinnamonMetal 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.