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

Simple question: Click to create a point

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 587 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.
  • B Offline
    bardlind
    last edited by 27 Nov 2015, 14:28

    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 ๐Ÿ˜„

    1 Reply Last reply Reply Quote 0
    • S Offline
      sdmitch
      last edited by 27 Nov 2015, 16:02

      @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
      
      

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

      1 Reply Last reply Reply Quote 0
      • B Offline
        bardlind
        last edited by 27 Nov 2015, 18:33

        Thanks alot! I will give it a try.

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

        Advertisement