What? No Menu?
-
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