What? No Menu?
-
See attached screenshot;
Notepad shows the content of the only non-Google plugin in the Plugins folder. It just adds a menu item to Plugins.
But when I type the same code in the Console, no menu is added. Why??
-
Weird!
If you send the following at the console, it works:
UI.menu('Plugins').add_item('Hello') { puts "World" }
Another thing. Each time you call
UI.menu('Plugins')
a new object is returned. I would think each of the standard menu objects would be created by the OEM extensions at startup, and theUI.menu
method should return those, every time the method is called.Is this a bug that has creeped into the latter versions?
-
@dan rathbun said:
Weird!
"Maddening" was my thoughts on this. I really thought Iwas going mad as I thought I was doing something wrong. I spent and hour on this yesterday. Was testing some code in the console. Before I tried to paste it into a file.
@dan rathbun said:
Another thing. Each time you call UI.menu('Plugins') a new object is returned. I would think each of the standard menu objects would be created by the OEM extensions at startup, and the UI.menu method should return those, every time the method is called.
That had me puzzled as well.
The thing is, if you don't have any plugins installed, and you typeUI.menu('Plugins')
into the console, the Plugins top menu appear, but you still can't add menus to it via the console.@dan rathbun said:
Is this a bug that has creeped into the latter versions?
Dunno - didn't try any earlier versions...
-
Same thing in SU6.
-
That has always worked for me and still does. I typically use it to quickly reload a file:
UI.menu('Plugins').add_item("Reload and Run") { load "my_file.rb"; do_method }
-
Yes,
UI.menu('Plugins').add_item('Hello') { puts "World" }
works.But does
x = UI.menu('Plugins') x.add_item('Hello') { puts "World" }
work for you? -
No, but this does:
x=UI.menu('Plugins');x.add_item("hi") { puts "hi" }
(single line.)
-
...
This makes no sense...
-
I think it has something to do with the fact that
UI.menu()
returns a new object each time:UI.menu("Plugins") #<Sketchup;;Menu;0x5dbf1c0> UI.menu("Plugins") #<Sketchup;;Menu;0x5dbeff8> UI.menu("Plugins") #<Sketchup;;Menu;0x5dbee30> UI.menu("Plugins") #<Sketchup;;Menu;0x5dbec68> UI.menu("Plugins") #<Sketchup;;Menu;0x5dbeaa0>
-
But still.... the exact same code saved as a .rb works.
-
That's because the code is executed all during one frame, which also explains why the one-liner works.
My guess is that Sketchup creates a new menu , adds the items, and does the validation each frame, instead of just using one menu.
-
frame?
-
I suppose refresh is a better term. I was referring to a frame in animation.
-
Thread may be a better word.
Examine the eval.c file in the Ruby source and you'll see that files are treated a bit differently.
-
@cjthompson said:
That's because the code is executed all during one frame, which also explains why the one-liner works.
My guess is that Sketchup creates a new menu , adds the items, and does the validation each frame, instead of just using one menu.
This is exactly right. It depends on the context available when commands are executed.
Another way to specify multi-line commands in Ruby is to use ''
You could do:x = UI.menu('Plugins') \ x.add_item('Hello') { puts "World" } \ x.add_item('Hello2') { puts "World2" }
and it would work and be all executed as a single command.
Advertisement