I can’t find anything later related to my topic title than this example from about five years ago.
And the code I copied from there doesn’t seem to work for me.
I want to validate user input as a valid SU length.
I’ve tried using this code to replace my inputbox, but while there is an error showing in the Ruby console, it isn’t coming from the replacement inputbox, but from later in the code where I try to convert the (invalid) input into a length.
def inputs(*args) results = nil begin results = UI.inputbox(*args) puts "Results from inputs = " + results.inspect rescue ArgumentError => error UI.messagebox error.message if args.length > 0 retry end end results end
I added the
puts line just to make sure that my active code IS using this replacement for the inputbox. It is.
If I deliberately enter an invalid length as
40g in the second (text) field expecting a length value (the default set is
0.inch), the code isn’t triggering the
messagebox but just shows this in the Ruby console while closing the inputbox on screen.
Results from inputs = ["14'", "40g", "4'", "0\"", "1\""] Error: #<ArgumentError: Cannot convert "40g" to Length> /Users/JohnWMcC/Library/Application Support/SketchUp 2020/SketchUp/Plugins/scenery.rb:161:in `to_l'
And that’s from a much later line where I am converting the value retrieved from the text box to length using
Does that mean I have to do the error trap at that point, since the
inputs method replacing
inputbox isn’t trapping the error there?