Contents Menu to other menu locations
-
Question is it possible to move any or all context menu plugins to another menu, i.e. Tools or Edit? Seems I am getting to many context menu items and I would like to move some of the plugins to either tools or edit. Are context menu plugins stuck in the context menu selection?
Ken
-
I guess it would be possible. The code where a menu item should appear is generally somewhere at the end of the scripts (AFAIK).
Not that I could (probably) modify one successfully... -
Yes.
BUT you need to rewrite the context-menu code...
For example [made up!]...UI.add_context_menu_handler do |menu| menu.add_item("Edges from Guide Lines"){xLine2Line()} end
would become something like
UI.menu("Plugins").add_item("Edges from Guide Lines"){xLine2Line()}
-
Thanks TIG
Now what I want to know is how did you guess the line_converter.rb is the very plugin that I wish to change.
And another question, is there any reason beyond just making it easy to select something and have a context menu pop up, or are there programing restraints that require the context menu.
I would prefer that no other context menu be written since Sketchup seems to have trouble handling these plugins.
Again thank you TIG
Ken
-
@unknownuser said:
Thanks TIG
Now what I want to know is how did you guess the line_converter.rb is the very plugin that I wish to change.
And another question, is there any reason beyond just making it easy to select something and have a context menu pop up, or are there programing restraints that require the context menu.
I would prefer that no other context menu be written since Sketchup seems to have trouble handling these plugins.
Again thank you TIG
Ken
The code that sets the menu is usually at the end of the script [some, like thomthom are perverse and put it at the start!] Do a 'find' on the script's text for 'menu' or 'context'... that's the code you need to adjust...
Context menus that are properly st up work fine - they only appear when a specific set of circumstances coincide - e.g. SectionCutFace only appears in the context-menu when you have a one item selection containing a SectionPlane... Sometimes context-menus are used when they are NOT necessary... -
TIG
I my studies of Ruby for Sketchup, I have no problem with finding the context menu, it just seems to me there is always an "if then" statement, proceeding the menu add statement, and I don't see on this the other menus. There are some plugins that appear in more than one menu, and I usually turn off the context menu, and move the plugin to an other memu selection where I wish to have the plugin appear. However, I have not been able to master the coding to get rid of just a context menu with the "if selection is.....".
Anyway, I will keep trying.
Thank
Ken
-
@unknownuser said:
TIG
I my studies of Ruby for Sketchup, I have no problem with finding the context menu, it just seems to me there is always an "if then" statement, proceeding the menu add statement, and I don't see on this the other menus. There are some plugins that appear in more than one menu, and I usually turn off the context menu, and move the plugin to an other memu selection where I wish to have the plugin appear. However, I have not been able to master the coding to get rid of just a context menu with the "if selection is.....".
Anyway, I will keep trying.
Thank
Ken
The code pseudo-code...
if this is not loaded then load it [i.e. make menu items etc] end Now it's loaded
code is there to ensure the menu only loads once even if the script is re-loaded... -
TIG
If was more of this type of code. Note, I have tried to remove context menu and add this to the Tools menu. So far, haven't had it to work. However, I am still working on it. What I was wondering, if the two line are required to make sure I that I have picked either a line or xline. Still working on it.
if( not file_loaded?("xLine.rb") )
UI.add_context_menu_handler do |menu|
if xLine_validate_selection [b]###THIS LINE RIGHT HERE[/b]
menu.add_separator
menu.add_item("Convert lines to guide lines") { xLine }
end
if line_validate_selection [b]### AND THIS LINE[/b]
menu.add_separator
menu.add_item("Convert guide lines to lines") { xLine2Line }
end
end -
The
file_loaded
part checks if the file was already loaded,
Theif xLine_validate_selection
part is a check to see if the selection includes suitable entities.
If you put a # in front of the 'if' and also in front of its final 'end' then that check is disabled.
Alternatively, add a line into thedef xLine_validate_selection
to return true always...
SO on the line immediately after the 'if' line addreturn true
and then the rest of the checking code is ignored anyway.... -
@unknownuser said:
TIG
I my studies of Ruby for Sketchup, I have no problem with finding the context menu, it just seems to me there is always an "if then" statement, proceeding the menu add statement, and I don't see on this the other menus. There are some plugins that appear in more than one menu, and I usually turn off the context menu, and move the plugin to an other memu selection where I wish to have the plugin appear. However, I have not been able to master the coding to get rid of just a context menu with the "if selection is.....".
Anyway, I will keep trying.
Thank
Ken
You could write a intermediate method to do the check. If ok, it runs the plugin. If not valid, then it pop up an error message:
def xLine_check_valid if xLine_validate_selection xLine else UI.messagebox "Invalid selection" end end if( not file_loaded?("xLine.rb") ) UI.menu("Plugins").add_item("Convert lines to guide lines"){xLine_check_valid} end file_loaded("xLine.rb")
Advertisement