Jump to content

Invalid node name in while loop ?


CinnamonMetal

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
Link to comment
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
Link to comment
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" ?

 

Link to comment
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
Link to comment
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 ?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...