Some defaults in inputbox not recognised

defaults
inputbox

#1

I have created a quick Ruby program to draw quarter-elliptical faces, some at a slant, to make a quarter of a large arch, structural columns and elevator shafts.

I have set up an array of defaults, but of the seven input fields, only five are being set initially to the specified defaults.

Inputs 3 and 4 just repeat defaults 0 and 1.

Here are what I think are relevant fragments of the code:

def initialize
    @defaults = [930.75.feet, 875.5.feet, 0.0, 917.9167.feet, 862.6667.feet, 0.0, 0.feet, "OTR elev", "No" ]
end
  ...
    def get_inputs()
      ## Get user input parameters for arch section#######################
      defaults = @defaults
      prompts = ["Major semi-axis 1           ", "Minor semi-axis 1         ", "Slope 1 (between -1 and +1)         ",
        "Major semi-axis 2         ", "Minor semi-axis 2         ", "Slope 2 (between -1 and +1)         ",
        "y_offset",  "Name", "Add floor numbers?"]

  list = ["930'9|929'9|928'5|918'5|917'11","875'6|874'6|873'2|863'6|862'8","0.0","930'9|929'9|928'5|918'5|917'11","875'6|874'6|873'2|863'6|862'8","0.0","0|10'2","","No|Yes"]

      input = UI.inputbox(prompts, defaults, list, "Arch section parameters" )
  
      if defaults.nil? || defaults.empty?  # not previously defined defaults or input
        defaults = @defaults
        if !input.empty?
          # remember inputs ready to adapt for next section of arch
          @defaults = input
        end
      end

      if input
        a1 = input[0].to_l
        b1 = input[1].to_l
        slope1 = input[2].to_f
        a2 = input[3].to_l
        b2 = input[4].to_l
        slope2 = input[5].to_f
        y_offset = input[6].to_l
        component_name = input[7]
        show_floor_numbers = input[8] == "No"? false : true

        if slope1.abs >1 || slope2.abs >1
          UI.messagebox "Slope must be between -1 and +1. Please try again", MB_OK
        end
        if b1 > a1 || b2 > a2
          UI.messagebox "Major axis must be larger than or equal to minor axis", MB_OK
        end
      else
        UI.messagebox "Sorry, invalid values, please try again", MB_OK
      end
      @defaults = input
...

What I get when I run this is:

Inputs Major and minor semi-axis 2 should be showing defaults of 917.9167.feet, 862.6667.feet, (that’s 917ft 11in, 862ft 8in) but are showing the same as semi-axes 1. When I pick the correct values in the drop down lists, they work correctly. It’s just the default isn’t selected.

Is it just because the decimal representation isn’t being recognized as the same as the list value, which is in ft and in? So what is showing (I’ve just realised) is the first value in each of the drop-down lists, which are the same for a1 and a2, and also for b1 and b2.

Is there a way round that? Could I use a literal string in the @defaults array and have it interpreted as a length?

It isn’t a show stopper, but I have to run the code multiple times, and it’s a pain to have to reset the starting values every time.


#2

Answering my own question. It seems I was being too clever by half in using decimal feet in the @defaults string.

If I just set the @defaults values to strings representing a length, like "917'11" it sets the value to match the list string, selects it as default, and the rest of the code sets the type of that input to length.


#3

Time to review ThomThom’s blog on units and inputbox:


#4

Thanks, Dan. I have read it, but worth a re-read in light of this experience.


#5

This topic was automatically closed after 91 days. New replies are no longer allowed.