sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Problem with input box displaying values

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 5 Posters 674 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P Offline
      peweuk
      last edited by

      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 from

      h1 = 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.

      1 Reply Last reply Reply Quote 0
      • T Offline
        todd burch
        last edited by

        Try this:

        h1 =(hhd-5.mm).to_l

        by adding the "to length" method onto it.

        1 Reply Last reply Reply Quote 0
        • Didier BurD Offline
          Didier Bur
          last edited by

          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 SU πŸŽ‰

          Hope this helps,

          DB

          1 Reply Last reply Reply Quote 0
          • P Offline
            peweuk
            last edited by

            Gee - such quick responses. Thanks guys - and even two ways of doing it πŸ‘

            Todd:
            tried this and it works ok

            Didier:
            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 😞

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by

              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.

              Hi

              1 Reply Last reply Reply Quote 0
              • fredo6F Offline
                fredo6
                last edited by

                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


                Tutorial for Ruby script programmers

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement