Mouse operations in Ruby

Hello everybody
Please is there a very detailed course on the functioning of the mouse because until now I can not control how the mouse works and how to recover the coordinates of a selected point?
something else is there small program that lets me see how the mouse buttons work when I click on them, like displaying a message telling me that the left button is clicked when I click on it.
thank you to all of you

I’m guessing this is a developer question and not how do you use a mouse.
If it is the OP should move it to the correct category or comment here and we can do it for you.

1 Like

Inside or outside SketchUp, Fred?

1 Like

merci pour vous tous
je parle de l’intérieur de sketchup , par exemple comment je dois faire pour que quand je clicke sur le bouton de la souris (gauche), un texte s’affiche dans me disant que j’ai clické sur le bouton gauche de la souris ? ça c’est la première partie
la deuxième partie, comment je peux récupérer les coordonnées 2d par rapport à l"ecran et 3d par rapport à l’espace sketchup d’un point d’une façon pure et simple ?
Merci d’avance à vous tous

Parlez-vous dans un script rubis? ou tout simplement en utilisant sketchup?

1 Like

dans un script rubis je vais poster un exemple que je le test depuis tout à l"heure mais ça fonctionne pas
‘’‘def onLButtonDown
UI.messagebox(“hi”)
end ‘’’

TRANSLATION in a ruby script I will post an example that I have been testing for a while ago "but it doesn’t work
‘’ 'Def onLButtonDown
UI.messagebox (“hi”)
end ‘’ ’

Je ne sais pas. je modifie le titre et la catégorie de votre question pour que quelqu’un qui comprenne l’écriture d’extension le remarque. bonne chance.

1 Like

very old test script to play with…

# Copyright 2005, @Last Software, Inc.

# This software is provided as an example of using the Ruby interface
# to SketchUp.

# Permission to use, copy, modify, and distribute this software for
# any purpose and without fee is hereby granted, provided that the above
# copyright notice appear in all copies.

# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#-----------------------------------------------------------------------------

require 'sketchup.rb'

class ToolTests

  # Called when you select the tool
  def activate
    puts "activate called"
  end

  # Called when I select another tool or quit SketchUp
  def deactivate(view)
    puts "deactivate called"
  end

  # Called when I roll middle mouse button?
  def draw(view)
    puts "draw called"
  end

  # Called when I roll middle mouse button?
  # Called when I bring SketchUp into view. Followed directly by draw
  def getExtents
    puts "getExtents called"
  end

  # This is called followed directly by onRButtonDown
  def getMenu(menu,flags, x, y, view)
    # add a menu_items here and the call comsumes both Down and up
    menu.add_item("eats onRButtonDown?"){
      puts "'getMenu called', is onRButtonDown above and onRButtonUp below? "
    }
   menu.add_item("capture onRButtonUp"){
     puts "call onRButtonUp from getMenu item{}... "
   onLButtonUp(flags, x, y, view)
   }
  end

  # Called when I press the Esc key. Followed directly by onKeyDown
  def onCancel(reason, menu)
    puts "onCancel called"
  end

  def onKeyDown(char, rpt, flags, view)
    puts "onKeyDown called"
  end

  def onKeyUp(char, rpt, flags, view)
    puts "onKeyUp called"
  end

  # NOTE: Called after onLButtonDown and onLButtonUp.
  def onLButtonDoubleClick(flags, x, y, view)
    puts "onLButtonDoubleClick called"
  end

  def onLButtonDown(flags, x, y, view)
    puts "onLButtonDown called"
  end

  def onLButtonUp(flags, x, y, view)
    puts "onLButtonUp called"
  end


  # Called a lot so I did not put a puts message in
  def onMouseEnter(view)
  
  end

  # Called a lot so I did not put a puts message in
  def onMouseLeave(view)

  end

  # Called a lot so I did not put a puts message in
  def onMouseMove(flags, x, y, view)
  end

  # NOTE: Called after onrButtonDown and onRButtonUp.
  def onRButtonDoubleClick(flags, x, y, view)
    puts "onRButtonDoubleClick called"
  end

  def onRButtonDown(flags, x, y, view)
    puts "onRButtonDown called"
  end

  # Called not only right after a onRButtonDown, but after a onRButtonDoubleClick?
  def onRButtonUp(flags, x, y, view)
    puts "onRButtonUp doubleclick called"
  end

  # NOTE: onReturn is followed directly by onKeyDown
  def onReturn(view)
    puts "onReturn called"
  end

  def onUserText(text, view)
    puts "onUserText called"
  end

  # Called when I double-click middle mouse button (exits out of orbit)
  def resume(view)
    puts "resume called"
  end

  # Called when I press middle mouse button (goes into orbit)
  def suspend(view)
    puts "suspend called"
  end

end # end of class ToolTests

Sketchup.active_model.select_tool ToolTests.new

john

1 Like

merci beaucoup j’ai testé sur le console ruby et ça marche super bien , je vais l’étudier ligne par ligne, par contre auriez vous un exemple concernant la récupération des coordonnées 2d(par rapport à l’écran) et 3d d’un point quand je clique n’importe où sur la fenêtre sketchup
merci beaucoup

another v5 SU one…

utilitiesTools.rb (7.4 KB)

john

Within the test tool change onLButtonUp to …

    def onLButtonUp(flags, x, y, view)
      puts "onLButtonUp called. User clicked at [#{x},#{y}]"
    end

Within the test tool change onLButtonUp again and create an inputpoint …

    def onLButtonUp(flags, x, y, view)
      puts "onLButtonUp called. User clicked at [#{x},#{y}]"
      @ip = view.inputpoint(x,y)
    end

REF:

1 Like

merci beaucoup grand dan
mais le deuxième exemple ne me donne pas les coordonnées en 3d , il me donne toujours les coordonnées 2d , y a t elle une chose à modifier ?
merci

re grand dan
j’ai réussi à récupéré les coordonnées 3 d en ajoutant "point= @ip.position "
néanmoins , merci beaucoup à vous tous, grâce à vous tous j’ai appris des choses
merci beaucoup

1 Like

Yes, this is why I gave you the link to the Sketchup::InputPoint class, so thta you could use the #position instance method.

You are most welcome. :smiley:

Vous êtes les bienvenus.


For more on using the mouse within a tool, see the SketchUp Development Team’s example "linetool.rb" file …

Pour en savoir plus sur l’utilisation de la souris dans un outil, consultez l’exemple de fichier "linetool.rb’ de l’équipe de développement SketchUp …

:bulb:

1 Like