Using the Cancel btn, to return to previous menu?
-
Short of tearing my hair out, of which I already have too few to part with. I don't seem to be able to get any menu to appear each time I add @results to my cancel.rb script. Neither does the ruby console identify any errors.
I suppose part of my problem is not understanding how "OK" and "Cancel" magically become part of any dialog box. There is no specific Ruby code identifying either of those terms, in the script.
=begin # Name; Cancel # Description; Initiate Cancel routine in Dialog Box #2 # returning user back to Dialog Box #1 # Date; 2012/21/08 # revised 2012/03/09 not working! #--------------------- ------------------------------------------------------ =end require 'sketchup.rb' module CANCEL #--------------------------------------------------------------------------- #Set default settings @height = 9.feet if not @height # floor to floor height @riser = 16 if not @riser # no. risers total def self.cancel # Dialog box #1 def dialog1() prompts = ["Floor/Floor Height ", "No. Risers"] values = [@height, @riser] @results1 = inputbox prompts, values, "Dialog Box #1" if @results1 dialog2() else return nil end end return if not @results1 @height, @riser = @results1 @riserheight=@height/@riser # riser height # Dialog box #2 def dialog2() prompts = ["My RiserHeight ", "--------"] values = [@riserheight, @any_entry] @results2 = inputbox prompts, values, "Dialog Box #2" if @results2 else dialog1() end end return if not @results2 @riserheight, @any_entry = @results2 end #self.cancel end #module CANCEL #--------------------------------------------------------------------------- if( not file_loaded?("cancel.rb") ) UI.menu("Plugins").add_item("Cancel") { CANCEL.cancel } end #--------------------------------------------------------------------------- file_loaded("cancel.rb") # load"cancel.rb"
-
You haven't followed my template
Try this...=begin # Name; Cancel # Description; Initiate Cancel routine in Dialog Box #2 # returning user back to Dialog Box #1 # Date; 2012/21/08 # revised 2012/03/09 not working! TIG'd 201201003 ! #--------------------- ------------------------------------------------------ =end require 'sketchup.rb' module CANCEL #--------------------------------------------------------------------------- #Set default settings @height = 9.feet if not @height # floor to floor height @riser = 16 if not @riser # no. risers total def self.cancel # Dialog box #1 def dialog1() prompts = ["Floor/Floor Height ", "No. Risers"] values = [@height, @riser] @results1 = inputbox prompts, values, "Dialog Box #1" if @results1 @height, @riser = @results1 @riserheight=@height/@riser # riser height dialog2() else return nil end end # Dialog box #2 def dialog2() prompts = ["My RiserHeight ", "--------"] values = [@riserheight, @any_entry] @results2 = inputbox prompts, values, "Dialog Box #2" if @results2 @riserheight, @any_entry = @results2 puts "Got here !" [@height,@riser,@riserheight,@any_entry].each{|e| puts e} else dialog1() return nil end end end #self.cancel ### unless file_loaded?(__FILE__) UI.menu("Plugins").add_item("Cancel") { CANCEL.cancel } end ### file_loaded(__FILE__) # load"cancel.rb" end #module CANCEL
-
@tomot said:
I don't seem to be able to get any menu to appear each time I add
@results
to my cancel.rb script.dialog not menu. A menu is a list of items, that drops down from the application menubar, (or pops up when you click the right mouse button.)
@tomot said:
I suppose part of my problem is not understanding how "OK" and "Cancel" magically become part of any dialog box.
(1) It's a standard Windows API function, that the SketchUp API wraps in a Ruby method.
(2) You are discussing a certain sub-type of dialog box, called an inputbox, which always gets an OK and Cancel button.
@tomot said:
There is no specific Ruby code identifying either of those terms, in the script.
Because if the user cancels, the return value evals false, otherwise the return value is an array (even if the user changed nothing,) which evals as not false. (Even an empty array and an empty string in Ruby will eval logically as not false.)
This is why we always do
return unless results
or
if results
just after theresults = UI.inputbox( ... )
call.Another sub-type of dialog box, is the messagebox. With that you CAN specify the button set, using constants that begin "MB" (such as
MB_OK
,MB_YESNOCANCEL
, etc.)
With a messagebox, you DO check the integer return value against the constantsIDYES
,IDNO
orIDCANCEL
, etc. -
@tig said:
You haven't followed my template
Try this...I tried your code, but it does not produce an on screen dialog either
-
@dan rathbun said:
Another sub-type of dialog box, is the messagebox. With that you CAN specify the button set, using constants that begin "MB" (such as
MB_OK
,MB_YESNOCANCEL
, etc.)
With a messagebox, you DO check the integer return value against the constantsIDYES
,IDNO
orIDCANCEL
, etc.Dan thanks for your comments. which raises one question. Would it then be possible to construct a single dialog box with a 3rd button ie. Calculate btn? Which in my example would calculate the division.
-
Learn web-dialogs and then you can have any buttons you want, called anything you want, doing anything you desire...
-
You only have two choices to construct dialogs with custom controls:
(1) Write native code for the platform your on, making system calls. (Very low-level nitty gritty advanced programming.)
(2) Write a WebDialog and use a HTML form.
@TIG EDIT: PUNCHBUG!
-
@dan rathbun said:
You only have two choices to construct dialogs with custom controls:
(1) Write native code for the platform your on, making system calls. (Very low-level nitty gritty advanced programming.)
(2) Write a WebDialog and use a HTML form.
]There is a (3) option. Maybe Trimble will add some more stuff to the SketchUp Ruby API, however I'm not holding my breath!
-
@tig said:
Learn web-dialogs and then you can have any buttons you want, called anything you want, doing anything you desire...
Luckily I have shortened my list of things that I desire. However if I were, and if I was my 20's, I would not waste my time learning web-dialogs. I'd learn COBOL, an almost extinct language, yet COBOL still runs 90% of the worlds financial programs. And since there are almost no COBOL programmers left, since most have or are retiring. One could make a great deal of money learning COBOL instead of Web-dialogs.
However that still does not answer my followup question: why does the Cancel dialog not display with your included revisions?
-
OMG! I had to take COBOL in college. I hated it.
I always wanted to have a "COBOL Sucks!" T-shirt made.
-
Here's an example I know works as I have tested it...
require('sketchup.rb') module CANCEL_TEST #Set default settings @height = 9.feet if not @height # floor to floor height @riser = 16 if not @riser # no. risers total def self.run() self.dialog1() end # Dialog box #1 def self.dialog1() prompts = ["Floor/Floor Height ", "No. Risers"] values = [@height, @riser] @results1 = inputbox prompts, values, "Dialog Box #1" if @results1 @height, @riser = @results1 @riserheight=@height/@riser # riser height self.dialog2() else return nil end end # Dialog box #2 def self.dialog2() prompts = ["My RiserHeight ", "--------"] values = [@riserheight, @any_entry] @results2 = inputbox prompts, values, "Dialog Box #2" if @results2 @riserheight, @any_entry = @results2 puts "Got here !" [@height,@riser,@riserheight,@any_entry].each{|e| puts e} else self.dialog1() return nil end end ### unless file_loaded?(__FILE__) UI.menu("Plugins").add_item("Cancel") { CANCEL_TEST.run() } end ### file_loaded(__FILE__) # load"CANCEL_TEST.rb" end#module
IT is now properly structured to loop back into itself is needs be...
-
Thanks TIG:
I would never have been able to figure out the self.run routine on my own!
Advertisement