Some years ago I developed a tool which (more or less) worked in SU 2017 and 2018.
A R-click anywhere the drawing window (even in an empty part of it) would pop up a ‘context’ menu looking like this, from which to choose a softwood size before drawing a length of:
![image]()
The content was defined in a method def getMenu(menu)....end
using information from arrays defined earlier in the code.
It was called by a simple onRButtonDown
method within the Tool code.
def onRButtonDown flags, x, y, view
## Load plugin-specific R-click context menu
getMenu()
end
I’m working again with Steve Baumgartner (@slbaumgartner) to rework the code, and we are trying to replicate this behaviour in SU 2019.
Neither of us can work out why this worked at all - the getmenu()
call has no menu
parameter which the getMenu(menu)
method requires, and in SU 2019 it immediately throws a mismatched number of arguments: 1 required, 0 supplied
error (or words to that effect).
Somehow, SU2018 fills in a valid Menu object ID and the menu works fine. SU 2019 doesn’t, and the code errors.
Here’s a simplified version of the getMenu(menu)
method, with fixed text replacing the array values, and just with a fixed item in the menu shown as MF_CHECKED.
def getMenu(menu)
puts "getMenu called #{menu.inspect}"
menu.add_item("UK PAR/PSE") {} ## Displays type of timber (only PAR implemented so far)
menu.add_item("Softwood size (nominal)") {}
menu.add_separator
item1 = menu.add_item("1\" x 1\"") {"do action 1"}
menu.set_validation_proc(item1) { MF_UNCHECKED}
item2 = menu.add_item("2\" x 1\"") {"do action 2"}
menu.set_validation_proc(item2) { MF_CHECKED}
item3 = menu.add_item("3\" x 1\"") {"do action 3"}
menu.set_validation_proc(item3) {MF_UNCHECKED}
menu.add_separator
menu.add_item("Custom size (actual)") {}
menu.add_separator
item4 = menu.add_item("3/4\" x 1/2\"") {"do action 4"}
menu.set_validation_proc(item4) {MF_UNCHECKED}
end # def getMenu
Here’s what it pops up, when I replace the method in the tool with this simplified version.
![image]()
QUESTIONS
-
Why did it work at all, and where did SU 2018 get the menu object ID which it passes to the getMenu(menu)
method? (We entered some test code to show that the receiving function was given a Menu object and ID.)
-
Even if we don’t find out how it worked in SU 2018, how can we provide a menu object ID to the onRButtonDown (or …Up) event so the menu will work in SU 2019? Just use something like
size_menu = UI.menu("")
?
At least that doesn’t error when I try it in the Ruby console, and returns:
#<Sketchup::Menu:0x007f85491a2310>
-
And anyway, how does a context menu get triggered when you click on empty space in the model window?
AFAIK, context menus usually need an object to click on, to provide a suitable context.