Problem with input box displaying values
-
I have just started to use Sketchup and have inherited some scripts written by a previous colleague. I have to now set about learning what Ruby is all about, but have an immediate issue which is rather irritating me as I have done some searches and so far not found an obvious answer.
I have a script which was designed to build some panels using input from an inputbox, but we now need to create a second input box to allow the changes of some dimensions.
For example, an input box has 3 inputs with default settings, the script looks like this:
@unknownuser said:
prompts = ["Width ", "Height ", "Depth", ]
values = [550.mm, 720.mm, 18.mm]results = inputbox prompts, values, "Default Size" return if not results xxd, hhd, yyd = results h1 = hhd-5.mm
This information is then used later in the script to create a panel. And that's all OK
What we now need is to recall the 3 dimensions to a new input box for verification or changes.
But this input box needs to show the initial values for xxd, and also yyd, BUT it also needs to show the MODIFIED value of 'hhd' which is now 'h1'.
This is where I am at a loss.
The script I have used is@unknownuser said:
prompts = ["New Width ", "New Height ", "New Depth", ]
values = [xxd, h1, yyd]results = inputbox prompts, values, "New Size" return if not results xx, h2, yy = results
which returns the correct values for the width and depth, but for the height (h1) it returns an obscure value.
I have read through some of the articles on Ruby and think this has something to do with the way the value of 'h1' is generated fromh1 = hhd-5.mm
Although this value works in the script when creating the panel, the inputbox is seeing it differently.
Can someone enlighten me.
Thanks for any advice that may be forthcoming.
-
-
Use instance variables:
#Init for first use; @xxd = 550.mm if not @xxd @hh = 720.mm if not @hhd @yyd = 18 .mm if not @yyd prompts = ["Width ", "Height ", "Depth", ] values = [@xxd, @hhd, @yyd] results = inputbox prompts, values, "Default Size" return if not results @xxd, @hhd, @yyd = results @h1 = @hhd-5.mm
Advantages:
Next time the inputbox will be called, the three variables won't be re-initialized (because "not @xxd" is false).
@h1 will "keep" its value as long as the script is running and even after completion, it thus can be used elsewhere in the code where needed.BUT: the "weird" value of h1 is the value of hhd expressed in inches: internally, SU only deals with inches (yes I know this is stupid, but this is the way it is).
720.mm - 5.mm = 28.1496062992126 for SUHope this helps,
-
Gee - such quick responses. Thanks guys - and even two ways of doing it
Todd:
tried this and it works okDidier:
Now I understand where the value was coming from - as you say, weird that SU defaults to inches in this instance and not the scene default measurements.
I think I understand your remark about using Instance variables, but I had a problem with it.
Firstly, in your script you had @hh the start of line 3, but @hhd at the end. I assume that the first part should have been @hhd as well. And using this the script returned the correct values (as expected) in the first input box.
However, the value returned in the second input box is still in inches, so it didn't seem to have the desired effect -
peweuk,
I wrote this Inputbox class just for this reason.
Once created, you can show it any number of times. By default, it will use the last values entered.
-
For those interested in Windows-style dialog boxes (i.e. not Web dialogs), I had written a library Libtraductor.rbthat supports also language translation in dialog boxes and ease the checking of parameters (min, max, string patterns, ...). It also preserves defaults and previous values.
I use it in Bezierspline and in JointPushPull (and actually in other unpublished scripts).
Attached is the script, as well as a tutorial for programmers in English.
Here is a snippet of the interface
dlg = Traductor;;DialogBox.new title #Declaring fields, either string, numeric or unit-based numeric, or enumeration list; dlg.field_string symbol, label, default, validation_pattern dlg.field_numeric symbol, label, default, value_min, value_max dlg.field_enum symbol, label, default, enum_hash #Showing the dialog box; Hash_results = dlg.show hash_initial_values
to drop in Skecthup Plugins folder
Advertisement