sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Inpupoint pick problem

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 196 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.
    • 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
      
      
      1 Reply Last reply 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

        1 Reply Last reply 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