Hi seniors, I now need to create a right-click context menu add_context_menu_handler. Yes, it is triggered globally and is not a custom tool, so I cannot use a series of mouse monitoring methods to obtain the mouse position because the user who uses it is still 23 The previous version prevented me from using overlay. It is now known that the selected object can be obtained when right-clicking, but is it possible to obtain the mouse position? Because my ultimate goal is to determine whether the object (surface) at the mouse position has a material when the mouse right-clicks. If so, display the context menu and record the material. If this cannot be achieved, maybe I can only read the current The material displayed in the material bar is not very understandable for user interaction.
Usually this kind of task can be handled by examining the Sketchup::Selection.
You can instruct the user to pre-select a face…
… but the good news is if there is no selection already and the user right click on a face it will automatically selected so you can check the selection. E.g:
module Dezmo
module TestModule
@@loaded = false unless defined?(@@loaded)
extend self
def my_method()
#do your stuff
end
unless @@loaded
cmd = UI::Command.new("My Ultimate material handler"){
my_method()
}
UI.add_context_menu_handler{|menu|
face = Sketchup.active_model.selection.grep(Sketchup::Face).first
menu.add_item(cmd) if face && face.material
}
@@loaded = true
end
end
end
The limitation is: If the face in a question inside a component/group this will not work, you need to instruct user to go to the “right” editing context.
__
BTW:
There is no object in Ruby API called as surface
. It is just a name of connected Sketchup::Faces with a condition of:
A soft edge will cause the connected faces to be treated as a surface. This means that if you have Hidden Geometry off and select one face it will also select all faces connected with soft edges. A soft edge will also appear hidden.
However the Selection #is_surface? method is used to determine if the selection contains only all of the faces that are part of a single curved surface.
You can also write your own method to determine if the face is part of the surface and collect all other face part of this surface.
Yes, it seems that this is the only way. I need to indicate enough prompts to allow users to operate correctly.thanks!