Coordinates entered with InputBox
- 
 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 thisDave 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;")
- 
 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]#Height1Your 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... 
- 
 Thanks, it works 
- 
 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:inload' (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. 
- 
 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]
Advertisement

 
                             
                             
                             
                             
                             
                             
                            