• Login
sketchucation logo sketchucation
  • Login
🔌 Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Overwrite Eventhandler ?

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 290 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.
  • S Offline
    schorradt
    last edited by 30 Jan 2009, 19:01

    how can i overwrite a EventHandler from a SketchupTool?
    like SelektionTool:
    i want define my own FunctionBody on Event onLButtonDown ...
    can somebody help me?


    http://www.henryschorradt.de/

    1 Reply Last reply Reply Quote 0
    • S Offline
      schorradt
      last edited by 30 Jan 2009, 19:29

      class MyXObserver <  Sketchup;;ToolsObserver
      
       	def onActiveToolChanged (a,b,c)
      	UI;;messagebox(""+a.to_s+b.to_s+c.to_s+"");
      	end
      
      end #class 
      observer1 = Sketchup.active_model.tools.add_observer(MyXObserver.new) 
      
      

      can somebody explain me: why the first parameter "a" false is at me?
      the first Parameter of onActivateToolChanged must be a type of Tools, but i get a "false" , why?


      http://www.henryschorradt.de/

      1 Reply Last reply Reply Quote 0
      • A Offline
        avariant
        last edited by 30 Jan 2009, 20:08

        Implementing a tool is as simple as creating a class an implementing the methods.

        Look at the linetool.rb in examples

        
        class LineTool
        def initialize
        ...
        end
        def activate
        ...
        end
        
        etc...
        def onLButtonDown(flags, x, y, view)
        ...
        end
        ...
        end
        
        

        As for why the observer method is returning odd values... no idea, I'll have to try it.

        EDIT: I implemented a test observer and it works fine.

        
        class MyTestObserver < Sketchup;;ToolsObserver
        	def onActiveToolChanged(tools, name, toolid)
        		puts tools.to_s + " " + name.to_s + " " + toolid.to_s
        	end
        	
        	def onToolStateChanged(tools, name, toolid, xxx)
        		puts tools.to_s + " " + name.to_s + " " + toolid.to_s + " " + xxx.to_s
        	end
        end
        
        

        It ouput "#Sketchup::Tools:0x5c1b690 CircleTool 21096" to the ruby console.
        You'll notice there is a fourth parameter for onToolStateChanged. The API is wrong; it doesn't list that parameter but without it there will be an error.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement