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

    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.
    • schorradtS Offline
      schorradt
      last edited by

      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
      • schorradtS Offline
        schorradt
        last edited by

        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

          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
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement