Jump to content

Index of class on empty string


CinnamonMetal

Recommended Posts

I'm hung on a problem, with python.  hou.ui.readInput() produces a tuple; I have a while loop but I can't get the index item of the tuple which is the "OK" button of the class not to disappear if the string is empty ?

In other words, if the user clicks "OK" the dialog should not disappear.

 

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 nodeName[0] == 0 and nodeName[1] !="":
    intro = hou.node("/obj").createNode("geo","geometryA")
    superGeo = intro.createNode("sphere",nodeName[1])
    superGeo.setPosition([2.3,4.5])
    superGeo.setParms({"radx":2.3,"radz":4.2,"type":"bezier","rows":54})
    fileNode = hou.node("/obj/geometryA/file1")
    fileNode.destroy()
    superGeo.setRenderFlag(True)
else:
    while not nodeName[0] == nodeName[0]:
        hou.ui.displayMessage("You must supply a valid node name")
        break

 

Link to comment
Share on other sites

while True:
    btn, nodeName = hou.ui.readInput("what do you want",buttons=('OK',"Cancel"),default_choice=0,title="Name the sphere",close_choice=1)
    if btn == 0 and nodeName:
        intro = hou.node("/obj").createNode("geo","geometryA")
        superGeo = intro.createNode("sphere",nodeName)
        superGeo.setPosition([2.3,4.5])
        superGeo.setParms({"radx":2.3,"radz":4.2,"type":"bezier","rows":54})
        fileNode = intro.node("file1")
        fileNode.destroy()
        superGeo.setRenderFlag(True)
        break

 

Link to comment
Share on other sites

19 hours ago, CinnamonMetal said:

I one more question. 

How do I get the "OK" button to loop repeatedly if strictly the "OK" button is pressed ? I'm hacking away at this and I hope, that I solve this before hopefully your reply.

Do not use break keyword inside the if statement and you'll get an infinite loop.

Edited by Stalkerx777
Link to comment
Share on other sites

If I make an infinite loop when the user enters some text instead of the rest of the script executing; the else statement is executed and the variable = nodeName does an infinite loop completely ignoring to execute the script ?  

I want the infinite loop strictly for the OK button, although not for the CANCEL button.

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...