Inpupoint pick problem
-
Hi,
I am trying to make a simple tool, which starts by drawing a line. I looked in the linetool.rb file to see how that works, but theres a lot going on in there!!!
Anyway below is my tool which just has a couple of variables to store some pick points, trouble im have is i get an "undefined method pick" in the console. Do I need to include some other file? there is nothing else ncluded in linetool.rb. Any help appreciated.
require 'sketchup.rb' UI.menu("Tool").add_item("my tool") { Sketchup.send_action "showRubyPanel;" Sketchup.active_model.select_tool(My_Tool.new) } class My_Tool @ip1 = Sketchup;;InputPoint.new @ip2 = Sketchup;;InputPoint.new @point_flag = 1 def activate puts "Activate" end def deactivate(view) puts "Deactivate" end def onMouseMove(flags, x, y, view) puts "Mouse Moved" end def onLButtonDown(flags, x, y, view) puts "Lbutton Down" end def onLButtonUp(flags, x, y, view) if(@point_flag) @ip1.pick view, x, y @tool_flag = 0 else @ip2.pick view, x, y @tool_flag = 1 end end end #end of class My_Tool
-
Initialize your variable in the correct scope.
<span class="syntaxdefault"><br />class My_Tool<br /> def initialize<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">ip1 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">InputPoint</span><span class="syntaxkeyword">.new<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">ip2 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">InputPoint</span><span class="syntaxkeyword">.new<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">point_flag </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 1<br /> end<br /><br /> def activate<br /> puts </span><span class="syntaxstring">"Activate"<br /></span><span class="syntaxdefault"> end<br /></span>
Explanation:
http://sporkmonger.com/2007/2/19/instance-variables-class-variables-and-inheritance-in-ruby
http://railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/
Advertisement