Inputbox chedking for cancel
-
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 -
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
-
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 ...
-
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.
-
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
-
Sketchup::active_model.select_tool(nil) if results == false
But Jim is correct. Your boolean expression in the conditional
if
statement was incorrect.
Advertisement