I am trying to develop a custom tool which will allow the user to select a line and they will be given the slope distance, azimuth and zenith angle of the line. A small table with all that info will then appear on their screen.
I currently have a little bit of code written which you can see below:
class MySpecialLineTool
def onLButtonDown(flags, x, y, view)
puts "onMButtonDoubleClick: flags = #{flags}"
puts " x = #{x}"
puts " y = #{y}"
puts " view = #{view}"
UI.messagebox("You clicked somewhere in SketchUp.")
end
end
def self.activate_special_tool
Sketchup.active_model.select_tool(MySpecialLineTool.new)
end
unless file_loaded?(__FILE__)
menu = UI.menu('Plugins')
menu.add_item("Darrian's Special Line Tool") {
self.activate_special_tool
}
file_loaded(__FILE__)
end
This will add a tool under the 'Extensions' tab at the top of SketchUp called 'Darrian's Special Line Tool'. When you click on this tool, then click anywhere in SketchUp, a message box appears which says, "You clicked somewhere in SketchUp." But that's about it, I've hit a brick wall so far.
Below is a picture of what 'should' happen if the whole thing worked as intended. https://i.stack.imgur.com/DPmdF.png
I'm quite okay with the calculations. It's just being able to get the code to know that a line has been clicked and to retrieve the Delta X, Y and Z of that line in order to be able to calculate the slope distance, azimuth and zenith angle.
I'm not too concerned about starting and ending point. I am aware this will have an affect on the azimuth and zenith angle, but I was already thinking of providing information from both directions to the user.
I can provide more info if required.
Thanks for your help!
The code below might help you with creating class variables of the selected edge's vertex start & end positions of X, Y, Z coordinates. These values might be needed to calculate some math formulas. Let me know if it helped or not.
I recommend encapsulating your code with Ruby modules for variable or method names not clashing with other SketchUp scripts on the Plugins folder.