Question about menu.add_item
-
I just want to add all my plugins to one submenu.
I use a global variable to store the submenu.but it does not work.Is there a way to add defferent plugins to one submenu?
-
@wikii said:
amenu=UI.menu("Plugins").add_submenu("Test")
amenu.add_item("print 1"){print 1}I Run each line of the codes in Ruby Console , Only a submenu "Test" has been added in plugins menu."Print 1" does not show in the submenu "Test".
If I save the codes in a rb file and load it in Ruby Console,submenu "Test" and "Print 1" will be shown correctly.
why?
I've noticed this before as well. Dunno why. Some kind of bug.
-
Use
$wikii_submenu=UI.menu("Plugins").add_submenu("Wikii")
then later
$wikii_submenu.add_item("Print 1"){print 1} $wikii_submenu.add_item("Print 2"){print 2}
etc, should work...It works in the console because the $global is remembered.
Also setting a global reference [$] for your actual tool means that as long as the .rb file making the submenu loads first [start its file name with a ! or ###], then other scripts can access the submenu and add items to it too - that's how I manage many of my main Plugins, using submenus 0 to 9 logically named and ordered to contain similar types of tools... Other stuff lives 'loose' in Plugins menu or wherever...
Remember to use a $ name that's unlikely to be reused by some one else - e.g. $menu = bad idea as it could easily used by someone else, but $wikii_submenu likely to be 'uncommon'... -
@tig said:
Use
$wikii_submenu=UI.menu("Plugins").add_submenu("Wikii")
then later
$wikii_submenu.add_item("Print 1"){print 1} $wikii_submenu.add_item("Print 2"){print 2}
Thank you,TIG!
But,it does not work when I copy it to Ruby Console line by line.
Only "Wikii" has been added to plugins menu.
"print 1" and "print 2" do not show. -
WikiiI see what you me - buggy...
However it WILL work when scripted... -
@tig said:
WikiiI see what you me - buggy...
However it WILL work when scripted...I hope it works in different scritps,means that two scripts can add items to a same submenu.
-
-
@tig said:
@wikii said:
@tig said:
WikiiI see what you me - buggy...
However it WILL work when scripted...I hope it works in different scripts, means that two scripts can add items to a same submenu.
It does work in different scripts, if you use a $ variable - I already use it like that...
I test these two file.
Only 1.rb work well,2.rb can't add item into the submenu.
-
They DO work....
BUT you have to let Sketchup auto-load them as it starts.You can't push a new item into a submenu by manually loading script files later on, or typing the commands into the console.
If I put both of your .rb files into my Plugins folder and restart Sketchup then I get the ../Plugins/Wikii/ submenu with the two specified items added - each one created by their separate script using the $ global ref... -
I see.
Thank you,Tig!
Advertisement