Simple question: Click to create a point
-
Long time lurker and Sketchup user, first time poster. Hello!
I have finally gotten around to creating a little extension for Sketchup, which I will post later on. This is my first time coding in Ruby (and one of my first times coding, ever).
In the beginning of my script, I create two concentric circles which the rest of the code is based upon. For now, I have just entered the [x, y, z] coordinate for the center point manually. However, I would like to be able to do this:
Draw a line in Sketchup. Then select my tool from the extensions menu. Click the end of the line I just drew, and this point's xyz is used in my script as the center point.
I realize this is probably the simplest part of my script, but I have not been able to figure it out. Help is appreciated
-
@bardlind said:
Long time lurker and Sketchup user, first time poster. Hello!
I have finally gotten around to creating a little extension for Sketchup, which I will post later on. This is my first time coding in Ruby (and one of my first times coding, ever).
In the beginning of my script, I create two concentric circles which the rest of the code is based upon. For now, I have just entered the [x, y, z] coordinate for the center point manually. However, I would like to be able to do this:
Draw a line in Sketchup. Then select my tool from the extensions menu. Click the end of the line I just drew, and this point's xyz is used in my script as the center point.
I realize this is probably the simplest part of my script, but I have not been able to figure it out. Help is appreciated
Your plugin must be an interactive tool like this
#------------------------------------------------------------------------------------------------ # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted. #------------------------------------------------------------------------------------------------ # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, # WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #------------------------------------------------------------------------------------------------ # Name; Add Circles # By; Bardlind # Usage; Plugins>Add Circles #------------------------------------------------------------------------------------------------ require 'Sketchup' # unless file_loaded?(__FILE__) UI.menu("Plugins").add_item("Add Circles") { Sketchup.active_model.select_tool Bardlind;;Add_Circles.new } file_loaded(__FILE__) end # module Bardlind class Add_Circles def initialize @mod=Sketchup.active_model @ent=@mod.active_entities @sel=@mod.selection @ip=Sketchup;;InputPoint.new @status_text = "Pick End Point" end def onMouseMove(flags, x, y, view) @ip.pick view,x,y; view.tooltip = @ip.tooltip; view.refresh Sketchup;;set_status_text @status_text,SB_PROMPT Sketchup;;set_status_text "", SB_VCB_LABEL Sketchup;;set_status_text "", SB_VCB_VALUE end def onLButtonDown(flags, x, y, view) if @ip.vertex @rad1 ||= 10; @rad2 ||= 20; @sides ||= 24 values = UI.inputbox(["Radius1;","Radius2;","No. Sides;"],[@rad1,@rad2,@sides],"Add Circles") if values @rad1,@rad2,@sides=values @mod.start_operation "Add Circles" @ent.add_circle(@ip.position,Z_AXIS,@rad1,@sides) @ent.add_circle(@ip.position,Z_AXIS,@rad2,@sides) @mod.commit_operation else onCancel(flags,view) end else UI.beep end end def onCancel(flags,view) Sketchup.send_action "selectSelectionTool;" end def draw(view) if( @ip.valid? && @ip.display? ) @ip.draw(view) end end end end
-
Thanks alot! I will give it a try.
Advertisement