Right Click Menu Items  Topic is solved

Right Click Menu Items

Postby medeek » Sat Nov 11, 2017 5:37 pm

I’ve noticed with some plugins that when you create something within them you can then right click on the object and plugin specific items are shown in that menu.

I would like to do something like that for the truss and foundation plugin where a user can right click and then be shown the option to edit the roof or foundation assembly.

Can someone point me in the right direction for adding this type of functionality.
0
Nathaniel P. Wilkerson PE
Medeek Engineering Inc
design.medeek.com
User avatar
medeek 
PluginStore Author
PluginStore Author
 

Re: Right Click Menu Items  Topic is solved

Postby TIG » Sat Nov 11, 2017 6:12 pm

Here's a simple example from part of my SectionCutFace tool's code.
That tool actually ONLY works from the right-click context-menu, when there's a suitable selection...
Code: Select all
### Setup Context-menu
unless file_loaded?(__FILE__)
  UI.add_context_menu_handler{|menu|
    if TIG::SectionCutFace.ok()
      menu.add_item( "#{MENUTXT}" ){ TIG::SectionCutFace.new() }
    end
    ###...etc...###
  }
  file_loaded(__FILE__)
end #unless
To explain the parts a little...
The TIG::SectionCutFace.ok() method returns true if the current selection contains just one Section-Plane.
The MENUTXT is a Constant which I had set up earlier - so it can involve translations etc - you could just use a text-string.
If that context-menu item is chosen, then the TIG::SectionCutFace.new() method runs [using the selected Section-Plane]...
You can simply replace bits with your own methods etc.
You can add several possible methods, each with their own 'tests', which can have multiple hits etc if needed...
You can also add a menu item based on your tool-name, and add commands into that as they become appropriate - just like you do in the top menu bar with a sub-item set up...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Right Click Menu Items

Postby medeek » Sat Nov 11, 2017 7:27 pm

Thank-you for the example and explanations.
0
Nathaniel P. Wilkerson PE
Medeek Engineering Inc
design.medeek.com
User avatar
medeek 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: zer0se7en and 6 guests

Visit our sponsors: