On SketchUp one can request user input using a dialog window created with the UI.Inputbox
method. It is a basic task to ask for the dimension or length of some geometry the script will create afterwards.
Internally SketchUp uses Inches to define geometry. The user will give the answer in his/her localized dimension idiom: '1,5m' for 1.5 Meters. The built in SketchUp method .to_l
converts strings to length. See https://github.com/thomthom/SketchUp-Units-and-Locale-Helper#sketchups-shortcomings for reference.
I'm asking the user for a length as a string from UI.Inputbox
and then converting it to a length value using .to_l
but if the user types an invalid value I don't know how check or how to handle the error.
As my localized length inputs have ',' as the decimal separation (in Portuguese it is 1,5m not 1.5m), I'm not willing to ask for a floating point value.
prompts = ['Length']
defaults = ['1,2']
inputs = UI.inputbox( prompts, defaults ,'Length Input')
inputs[0].to_l
#try inputs[0].to_f
How check the input string or catch .to_l
failure?