Skip to content

Instantly share code, notes, and snippets.

@cmur2
Created August 25, 2012 13:08
Show Gist options
  • Save cmur2/3465399 to your computer and use it in GitHub Desktop.
Save cmur2/3465399 to your computer and use it in GitHub Desktop.
Sketchup PointCoordinates tool
# License: 2-clause BSD
require 'sketchup.rb'
class PointCoordinatesTool
def initialize
end
def activate
@last_pos = Sketchup::InputPoint.new
@pos = Sketchup::InputPoint.new
@drawn = false
Sketchup.set_status_text 'Coordinates', SB_VCB_LABEL
reset(nil)
end
def deactivate(view)
reset(view)
end
def draw(view)
if @pos.valid? and @pos.display?
@pos.draw view
#@drawn = true
end
end
def onMouseMove(flags, x, y, view)
@pos.pick view, x, y
if @pos != @last_pos
view.invalidate if @pos.display? or @last_pos.display?
@last_pos.copy! @pos
Sketchup.set_status_text @pos.position.to_s, SB_VCB_VALUE
# set the tooltip that should be displayed to this point
view.tooltip = @last_pos.tooltip
end
end
def onLButtonDown(flags, x, y, view)
@pos.pick view, x, y
if @pos.valid?
UI.messagebox(@pos.position.to_s)
end
end
def onCancel(flag, view)
reset(view)
end
def reset(view)
if not view.nil?
view.tooltip = nil
view.invalidate if @drawn
end
@last_pos.clear
@drawn = false
end
end
if not file_loaded?(__FILE__)
cmd = UI::Command.new('Point coordinates') do
Sketchup.active_model.select_tool PointCoordinatesTool.new
end
cmd.tooltip = 'Shows the coordinates of a point'
cmd.small_icon = "ToolPencilSmall.png"
cmd.large_icon = "ToolPencilLarge.png"
UI.menu("Plugins").add_item cmd
UI.toolbar("Plugins").add_item cmd
#UI.toolbar("Plugins").show if not UI.toolbar("Plugins").visible?
end
# CLI shortcut
def pctool
Sketchup.active_model.select_tool PointCoordinatesTool.new
end
file_loaded(__FILE__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment