sketchucation logo sketchucation
    • Login
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Inpupoint pick problem

    scheduled pinned locked moved Developers' Forum
    2 Posts 2 Posters 208 Views 2 Watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • C Offline
      Casey
      last edited by

      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
      
      
      one-reply-to-this-post last-reply-time reply quote 0
      • thomthomT Offline
        thomthom
        last edited by

        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/

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        one-reply-to-this-post last-reply-time reply quote 0
        • 1 / 1
        • first-post
          last-post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement