• Login
sketchucation logo sketchucation
  • Login
⌛ Sale Ending | 30% Off Profile Builder 4 ends 30th September

Issues with the onMouseMove method within a Ruby Tool

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 4 Posters 446 Views 4 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.
  • D Offline
    dagobo
    last edited by 11 Jul 2011, 09:31

    Hi all,

    I've got some troubles to understand the view.invalidate command implemented inside the onMouseMove method within a Tool Ruby script.

    This method is called to refresh the view and to allow the tool to draw some temporary graphics.

    If I want the draw method to draw something different either I clicked once or twice, can I create two draw methods (draw1 and draw2) ?
    Or should I use a variable (first_click=true or false) to tell the draw method which graphic it must draw ?

    Eventually, I don't want the draw method to draw simple lines in real time, but I want a component attribute to be modified (LenX) and immediatly displayed when the onMouseMove method is active.
    It is a bit like the Push-Pull method : can I tell the draw view to update the LenX attribute's value in real time and to display immediatly the component with the good dimensions ? Or should I use another method than the draw method to allow my onMouseMove method to do that in real time ?

    Thanks a lot for your help,

    Marie

    1 Reply Last reply Reply Quote 0
    • S Offline
      sdmitch
      last edited by 11 Jul 2011, 16:18

      dagobo, to start, you could add a variable @first_click = false, then in the onLButtonDown or onRButtonDown methods toggle it by @first_click = !@first_click. In the draw method, use a if then else statement to draw different things given the state of @first_click.

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 11 Jul 2011, 20:57

        SketchUp tools are event-driven - you do not decide when when the methods (defined by the Tool interface ) are called - SketchUp calls them. What you need to do is decide how to react depending on the state of your tool.

        Here's a very basic example:

        class MyTool
          def activate
            @state = 0
          end
          def onLButtonDown(flags, x, y, view)
            @state += 1
          end
          def onMouseMove(flags, x, y, view)
            case @state
              when 1; # Do this
              when 2; # Do that
              when 3; # do the other thing
            end
          end
        end
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • D Offline
          dagobo
          last edited by 18 Jul 2011, 10:06

          Thanks Jim.

          I am actually trying to implement my draw method within my tool ruby script that way :

          def draw view 
          	@component.set_attribute("dynamic_attributes","angle_h", @angle_horizontal_degres)
          	@component.set_attribute("dynamic_attributes","angle_v", @angle_vertical_degres)
          	$dc_observers.get_latest_class.redraw_with_undo(@component)
          end
          
          

          The draw method is called within my onMouseMove method.

          What I am trying to get is to make my tool draw and direct my component (@component) towards the right direction (given by both the attributes "angle_h" and "angle_v").

          For now, my script doesn't return any error message, but it doesn't do the right operation.
          My component is directed toward the same direction each time I compute the script, which is not the good direction.

          The lines I use to direct the component are perfectly working within my onLButtonDown method, but not within my onMouseMove method (through the draw method) as you can see.

          How could I fix this ?

          Thanks a lot,

          Marie

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 18 Jul 2011, 10:16

            def draw(view)
            is a standard method within a Tool class that is auto-called by Sketchup when any event happens that needs a [re]draw - like a onMouseMove ... you don't need to specifically 'call' it in your own code 😕
            http://code.google.com/apis/sketchup/docs/ourdoc/tool.html#draw
            Don't use draw but rather a new method called say def update() that is explicitly called from your onMouseMove method when certain conditions are met like so '@state' checking tests... Leave 'draw' to do it's own thing like draw some temporary graphics etc...

            TIG

            1 Reply Last reply Reply Quote 0
            • D Offline
              dagobo
              last edited by 19 Jul 2011, 12:10

              OK so if I make a simple draw method that way :

              def draw(view)
              	view.line_width = 3       
              end
              

              and if I create a draw_beam method that way :

              def draw_beam()
                 @component.set_attribute("dynamic_attributes","angle_h", @angle_horizontal_degres)
                 @component.set_attribute("dynamic_attributes","angle_v", @angle_vertical_degres)
                 $dc_observers.get_latest_class.redraw_with_undo(@component)
              end
              

              which I can call inside my onMouseMove, will it work correctly ?

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 20 Jul 2011, 09:34

                Why ask me?
                You are the one with all of the code...
                Just test it.

                You need to call your method self.draw_beam() within the onMouseMove method - probably after you've test for a certain 'state' being reached - e.g. perhaps initially 'draw_beam' doesn't kick in with @state=0, but after you have done some other stuff when you've then set @state=1 - then in the onMouseMove method the line would be self.draw_beam() if @state==1 etc, later on, perhaps after you click again, you'd set @state=2 so then the 'draw_beam' stops...

                TIG

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

                Advertisement