Jump to content
CinnamonMetal

Index of class on empty string

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.

 

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

 

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Share this post


Link to post
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.

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

×