Is disabling menu items and or tools possible?
-
I know that it's very easy to add menu items, tool bars, context menu items with Ruby in Sketchup, but I tried to disable/hide/remove and as far as I can see that's not possible.
Any suggestions?[Maggy]
-
Remove/Hide: Not on the running process
Grey=Disable: Depends on the scriptazuby
-
Thanks.
Grey sounds good enough. But the only grey I can find is in the class Color document.
Can you tell me where to find more information?[Maggy]
-
Yes, in the sketchup Ruby API documentation,
http://download.sketchup.com/sketchuphelp/gsu6_ruby/Docs/Ruby-Menu.html#set_validation_proc
But the example is a shame. So have a look on these few lines of code:grayed_proc = Proc.new { @active_model.path.empty? ? MF_GRAYED ; MF_ENABLED } azubymenu = UI.menu("Plugins").add_submenu "Cornflakes" azuby_menu_item = azubymenu.add_item "Add milk" do UI.messagebox "Adding milk to your cornflakes" end azubymenu.set_validation_proc azuby_menu_item, &grayed_proc # take care for the "&" or write the line; azubymenu.set_validation_proc azuby_menu_item do @active_model.path.empty? ? MF_GRAYED ; MF_ENABLED endAn equal usage is possible for toolbar items.
azuby
-
Why didn't I get Ruby in school, when I was 10 years old or so? Now, 40 years later it's very hard to grasp. The most frustrating part it that it looks so easy when I read a perfectly functioning ruby script. But it looks just as easy in a script that's not doing what I expect it to do...
I copied your code to "cornflakes.rb", loaded it, it shows up in Plugins, it adds milk to my cornflakes, but I do not see it grey out any menu item. So I started editing, editing, editing, each time closing SU, restarting it, reloading Cornflakes.rb till the milk and cornflakes were coming out of my ears, but still no greyed out menu items.
[Maggy]
-
Maybe because you have to set the @active_model before using the code - like this:
@active_model = Sketchup.active_modelI haven't ried the code and at the moment I'm in university and do not have Sketchup installed. I'll care this evening, if it won't work as expected.
azuby
-
For me this code works with the additional line. I put it to a .rb file, load Sketchup, try to use Plugins > Cornflakes > Add mild, it is grayed, I open a .skp file and try the same and get my breakfest.
azuby
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better š
Register LoginAdvertisement