SketchUcation Premium Membership

 

 

is disabling menu items and or tools possible?

is disabling menu items and or tools possible?

Postby Maggy » Tue Nov 27, 2007 5:20 am

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]
Maggy
 
Posts: 116
Joined: Tue Mar 11, 2008 2:09 pm

Re: is disabling menu items and or tools possible?

Postby azuby » Tue Nov 27, 2007 5:21 am

Remove/Hide: Not on the running process
Grey=Disable: Depends on the script

azuby
error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory* | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

Bad English? PM me, correct me. :)
azuby
 
Posts: 309
Joined: Mon Nov 12, 2007 3:36 pm
Location: Berlin (Germany)

Re: is disabling menu items and or tools possible?

Postby Maggy » Tue Nov 27, 2007 5:22 am

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]
Maggy
 
Posts: 116
Joined: Tue Mar 11, 2008 2:09 pm

Re: is disabling menu items and or tools possible?

Postby azuby » Tue Nov 27, 2007 5:30 am

Yes, in the sketchup Ruby API documentation,
http://download.sketchup.com/sketchuphe ... ation_proc
But the example is a shame. So have a look on these few lines of code:
Code: Select all
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
end


An equal usage is possible for toolbar items.

azuby
error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory* | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

Bad English? PM me, correct me. :)
azuby
 
Posts: 309
Joined: Mon Nov 12, 2007 3:36 pm
Location: Berlin (Germany)

Re: is disabling menu items and or tools possible?

Postby Maggy » Tue Nov 27, 2007 5:31 am

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]
Maggy
 
Posts: 116
Joined: Tue Mar 11, 2008 2:09 pm

Re: is disabling menu items and or tools possible?

Postby azuby » Tue Nov 27, 2007 5:32 am

Maybe because you have to set the @active_model before using the code - like this:
Code: Select all
@active_model = Sketchup.active_model
I 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
error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory* | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

Bad English? PM me, correct me. :)
azuby
 
Posts: 309
Joined: Mon Nov 12, 2007 3:36 pm
Location: Berlin (Germany)

Re: is disabling menu items and or tools possible?

Postby azuby » Tue Nov 27, 2007 5:32 am

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
error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory* | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

Bad English? PM me, correct me. :)
azuby
 
Posts: 309
Joined: Mon Nov 12, 2007 3:36 pm
Location: Berlin (Germany)

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Need SketchUp Books, Models, Styles or Textures? Check out our One Stop Shop for SketchUp.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012


Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 4 guests