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

    Coordinates entered with InputBox

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 2 Posters 741 Views 2 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.
    • D Offline
      davesexcel
      last edited by

      Very 1st attempt with Ruby Sketchup, I am trying to have somebody enter 3 numbers in input boxes and then draw the lines to create a rake.
      I don't know how to get the numbers entered into the coordinates.
      Thanks for any help in this

      Dave

      model = Sketchup.active_model
        entities = model.entities
        prompts = ["Hieght1", "Width","Height2"]
          defaults = [10,20,15]
          input = UI.inputbox prompts, defaults, "Rake Window."
      
          if input == false 
          UI.messagebox("All Must Be Entered")
          else
          UI.messagebox("Rake has been Drawn, #{input}!")
          end
          #Coordinates from inptut box
        pt1 = [0, 0, 0]
         pt2 = [0, 10, 0]#Height1
         new_face = entities.add_line pt1, pt2
        pt2 = [0, 10, 0]
         pt3 = [20, 15, 0]#Width
         new_face = entities.add_line pt2, pt3
        pt3 = [20, 15, 0]
         pt4 = [20, 0, 0]#Heights
         new_face = entities.add_line  pt3, pt4
        pt4 = [20, 0, 0]
         pt1 = [0, 0, 0]
         new_face = entities.add_line pt1, pt4
      
      
      Sketchup.send_action("viewFront;")
       Sketchup.send_action("viewTop;")
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        else
        a,b,c=input
        UI.messagebox("Rake DATA accepted!, #{input}!")

        Then use a, b or c as needed in your points...
        So when you have:
        pt2 = [0, 10, 0]#Height1
        make it
        pt2 = [0, b, 0]#Height1

        Your input would be logical as XYZ !!!
        It's aka RGB...
        Although you seem to want to use it as a weird set of ABC v XYZ coordinates...

        πŸ˜’

        TIG

        1 Reply Last reply Reply Quote 0
        • D Offline
          davesexcel
          last edited by

          Thanks, it works

          1 Reply Last reply Reply Quote 0
          • D Offline
            davesexcel
            last edited by

            Thanks, with your help I managed to clean it up a bit.
            I can draw the face now instead of just drawing the lines.

            I am now trying to select the face and offsetting it(Insetting).
            I can get the code to select it but it does not inset it.

            This is the error I get.
            **Error: #<NameError: undefined local variable or methodselection' for main:Object>
            C:/Program Files (x86)/SketchUp/SketchUp 2013/Plugins/first.rb:24
            (eval):24:in load' (eval):24**

            My final outcome will be to have a user input the rake dimensions. It will draw the rake and then draw the offset and move the offset to the right of the original.
            Basically, need the original, and then another one 1/4" smaller beside it.

            One thing at a time though

            This is the code I have so far.
            ` model = Sketchup.active_model
            entities = model.entities
            prompts = ["Hieght1", "Width","Height2"]
            defaults = [10,20,15]
            input = UI.inputbox prompts, defaults, "Rake Window."

            if input == false
            UI.messagebox("All Must Be Entered")
            

            else
            a,b,c=input
            UI.messagebox("Rake DATA accepted!, #{input}!")
            end
            #Coordinates from input box
            pt1 = [0, 0, 0]
            pt2 = [0, a, 0]
            pt3 = [b, c, 0]
            pt4 = [b,0,0]
            new_face = entities.add_face pt1, pt2, pt3, pt4
            Sketchup.send_action("viewFront:")
            Sketchup.send_action("viewTop:")
            #Select and offset
            model = Sketchup.active_model
            model.selection.add( model.active_entities.to_a )
            newFace = selection[1].offset(-.25)`

            Thanks for any replies.

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

              The last line
              newFace = selection[1].offset(-.25)
              is wrong!
              Try
              selection=model.selection newFace = selection[1].offset(-0.25)
              OR
              newFace = model.selection[1].offset(-0.25)
              πŸ˜„
              The error is actually quite clear - it is telling you that 'selection' hasn't been defined ...
              Note it's best to use 0.25 NOT .25
              Also how do you know what selection[1] is going to be ??? πŸ˜•
              The API's offset() method is to offset a point3d by a vector3d + an optional length
              BUT there is an offset() method that can be added for faces, edges etc - BUT this is added by another script [by Rick Wilson?], but I don't see you 'requiring' it at the start of your code... πŸ˜•
              πŸ˜’

              Another tip: your input...
              defaults = [10,20,15]
              fixes the inputs as integers, if you want the input in inched use decimal numbers:
              defaults = [10.0, 20.0, 15.0]
              OR
              defaults = [10.inch, 20.inch, 15.inch]

              TIG

              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