sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    What am I doing wrong?

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 6 Posters 827 Views 6 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.
    • J Offline
      JaViXP
      last edited by

      Hello,

      well, I was just trying do make an 'addition' to Chris' multi-pushpull plugin and this is what I've got so far:

      model = Sketchup.active_model
      sel = model.selection
      ent = model.active_entities
      
      height = mpp_options_diag
      
      faces = []
      	sel.each do |e|
      	
      		if e.is_a? Sketchup;;Face
      			faces << e
      		end
      	end
      	
      	faces.each do |face|
      	face.pushpull height.to_i
      end
      
      def mpp_options_diag
      	prompts = ["Insert the height for the Multi PushPull"]
      	defaults = ["100"]
      	input = UI.inputbox prompts, defaults, "Multi PushPull Tool Parameters"
      end
      

      Thing is, it lets me run the code if I do "face.pushpull(100)", but not with "face.pushpull height.to_i"

      The Ruby Console shows this error:

      undefined method `to_i' for ["100"];Array
      C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/webconsole/webconsole.rb;31;in `run'
      (eval);15;in `each'
      (eval);15;in `run'
      undefined method `to_i' for ["100"];Array
      
      

      What am I doing wrong then?
      Thanks. 😳

      "Giving up is way harder than trying"
      JaViXP's Rendering

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

        Hi Javier,

        Ruby methods will return the value of their last statement. In your code, the method mpp_options_dialog return the value of the input variable; which is a Array.

        So height == ["100"]. You need to get the first element of the Array. Here is one way:

        height = height[0].to_i

        Hi

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Also you might not want the height as an integer by using .to_i, because 0.5.to_i will become 0 not 1 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], and answer.class

          results=UI.inputbox(["Height: "],[1],[""],"My Title")
          for an integer - shown with
          answer=results[0], and answer.class

          results=UI.inputbox(["Height: "],["1.0"],[""],"My Title")
          for a 'string'- shown with
          answer=results[0], and answer.class and then
          answer.to_i answer.to_f answer.to_l

          [Try different answers to see the results...]

          TIG

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @tig said:

            BUT if you really want it to be a string - so for example the user can type '1.5m' and you get 1.5m - then use .to_l to convert it to a length...

            If you feed the inputbox a Length - then it will return a Length. No need for conversion. And the Length will even be displayed in the format of the model.

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              result = UI.inputbox( ['Width: '], [10.m], 'Hello World' )
              Type 50cm in the inputbox.
              ` > [19.6850393700787]

              result[0].class

              Length

              result[0].to_s

              500mm`

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

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

                Thank you everyone, for "clearing up" my doubts. It works fine now.
                By the way, just not to make a new topic for a single question, is is possible to load/unload/reload plugins with SketchUp running?

                "Giving up is way harder than trying"
                JaViXP's Rendering

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  @javixp said:

                  By the way, just not to make a new topic for a single question

                  That is actually better to make a new topic. New topic of conversation - new thread. Makes it easier to navigate and browse. Also makes the threads easier to follow with less topics.

                  @javixp said:

                  is is possible to load/unload/reload plugins with SketchUp running?

                  You can load (and reload) scripts by using the Ruby Console, typing load 'myRubyFile.rb'

                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • F Offline
                    Frankn
                    last edited by

                    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, because 0.5.to_i will become 0 not 1 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], and answer.class

                    results=UI.inputbox(["Height: "],[1],[""],"My Title")
                    for an integer - shown with
                    answer=results[0], and answer.class

                    results=UI.inputbox(["Height: "],["1.0"],[""],"My Title")
                    for a 'string'- shown with
                    answer=results[0], and answer.class and then
                    answer.to_i answer.to_f answer.to_l

                    [Try different answers to see the results...]

                    1 Reply Last reply Reply Quote 0
                    • F Offline
                      Frankn
                      last edited by

                      With some trial and lots of errors I figured it out. πŸ˜„

                      1 Reply Last reply Reply Quote 0
                      • Chris FullmerC Offline
                        Chris Fullmer
                        last edited by

                        Sorry we were so useless. Glad you figured it out, though!

                        Lately you've been tan, suspicious for the winter.
                        All my Plugins I've written

                        1 Reply Last reply Reply Quote 0
                        • F Offline
                          Frankn
                          last edited by

                          Trust me Chris you and everyone else who takes the time to help us new guys out are anything but useless. πŸ˜„

                          @chris fullmer said:

                          Sorry we were so useless. Glad you figured it out, though!

                          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