Sorry to dig up an old thread but It's kind of relevant to what I'm trying to do with inputbox.
What I'd like to do is associate a word with a value... ie: inputbox prompts for 3 values to create a square, height, width and vertical line... height and width are pretty self explanatory. Vertical line is expressed as inches.. so a 24" x 24" square could be divided in half by typing in 12... what I'd like to add is being able to type in 'center' or 'middle' and getting the same result.
I've tried making that field of the array a string and then converting the string to an integer or a float but I just can't get it to work... also tried associating the words to a value and samething no workie...
Hope that makes sense...
Thanks in advance.
@tig said:
Also you might not want the height as an integer by using
.to_i
, because0.5.to_i
will become0
not1
as you might have expected, as an integer simply ignores anything to the right of the decimal-separator !
The inputbox dialog can have its 'type' set to be a 'float' etc by making the default e.g. 1.0 [rather than 1 which fixes it as an integer] - then the dialogs returned_value[0] is always as a float anyway - BUT if you really want it to be a string - so for example the user can type '1.5m
' and they'll get 1.5m irrespective of the SKP's current unit settings - then use.to_l
to convert that value into a 'length'...Rather than add your dialog into a lot of complex code to test it just make it in a one-liner in the Ruby Console...
results=UI.inputbox(["Height: "],[1.0],[""],"My Title")
for a float - shown with
answer=results[0]
, andanswer.class
results=UI.inputbox(["Height: "],[1],[""],"My Title")
for an integer - shown with
answer=results[0]
, andanswer.class
results=UI.inputbox(["Height: "],["1.0"],[""],"My Title")
for a 'string'- shown with
answer=results[0]
, andanswer.class
and then
answer.to_i answer.to_f answer.to_l
[Try different answers to see the results...]