Jump to content
CinnamonMetal

Invalid node name in while loop ?

Recommended Posts

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 by CinnamonMetal

Share this post


Link to post
Share on other sites

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

 

  • Thanks 1

Share this post


Link to post
Share on other sites
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" ?

 

Share this post


Link to post
Share on other sites
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 by f1480187
  • Thanks 1

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×