• Login
sketchucation logo sketchucation
  • Login
🔌 Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Inputbox chedking for cancel

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 5 Posters 479 Views 5 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    ktkoh
    last edited by 18 Jun 2014, 20:05

    I am trying to check if the user selected cancel after looking at an input box. the api lists that it returns false however I have not found the way to check for this.

    prompts = ["Joint Face READ ONLY","LT Thickness","LT Width", "LT Length","Locate By; ","Tenon Depth Comp 1 ","Through Mortise? "]
        defaults = [@e_len1.to_s + " x " + @e_len2.to_s,@ans[7].to_s,@ans[2].to_s, @ans[8].to_s, @ans[9].to_s, @ans[3].to_s,@ans[15].to_s]
        choices =["","","","","Centered|Offset","","No|Comp 1|Comp 2|Both Comp"]
        results = inputbox prompts, defaults, choices, "Input Data for Loose Tenon Joint "
        if false then self.reset end; Sketchup.send_action "selectSelectionTool;"
        @thickness = results[1].to_l; @ans[7] = results[1]
        @width = results[2].to_l; @ans[2] = results[2]
        @length = results[3].to_l; @ans[8] = results[3]
        @locate_By = results[4]; @ans[9] = results[4]
        @lt_depth_C1 = results[5].to_l; @ans[3] = results[5]
        @thru_Mortise = results[6].to_s; @ans[15] = results[6]
    

    tried
    if results[] == false
    if results == false
    but all result in error undefined method `[]' for false:FalseClass>

    thanks
    Keith

    1 Reply Last reply Reply Quote 0
    • D Offline
      driven
      last edited by 18 Jun 2014, 21:02

      added the last line to the API example code, try it

        prompts = ["What is your Name?", "What is your Age?", "Gender"]
       defaults = ["Enter name", "", "Male"]
       input = UI.inputbox(prompts, defaults, "Tell me about yourself.")
      input == false ? "cancled" ; input
      

      john

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 18 Jun 2014, 21:02

        Yes, inputbox does return false when the user hits the Cancel button.

        If the code you posted is what you are using, there is a mistake where you use:

        
        if false ..
        
        

        where you meant to use:

        
        if results == false ...
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • S Offline
          slbaumgartner
          last edited by 18 Jun 2014, 21:10

          John and Jim beat me to the punch! Your code example does not do any of the tests you mention.

          UI.inputbox does return false when the user clicks cancel. This is easy to confirm via the Ruby Console. You can find examples in numerous plugins with code such as

          unless (results)... # abort when cancel

          if(results)... # proceed when not cancel

          if(results == false)... # again, abort when cancel

          The only one that won't work is results[], since false is not an Array.

          1 Reply Last reply Reply Quote 0
          • K Offline
            ktkoh
            last edited by 18 Jun 2014, 23:36

            Thanks for the answers. However as noted at the bottom of the post I had tried some of them already. I found that the error actually was telling me that I could not Quit the Tool by the statement

             Sketchup.send_action "selectSelectionTool;"
            

            and thus the program was trying to proceed with out the results[] from the input box. I did find a way to place a test and exit before the code made any changes to the model.

            No easy way to quit a tool??

            Keith

            1 Reply Last reply Reply Quote 0
            • D Offline
              Dan Rathbun
              last edited by 19 Jun 2014, 02:08

              Sketchup::active_model.select_tool(nil) if results == false

              But Jim is correct. Your boolean expression in the conditional if statement was incorrect.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                1/6
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement