Generally you are using parenthesis when you shouldn’t (around single conditional expressions following
unless,) and omitting them when you should always use them (around method parameters for object instance method calls. [Ruby is not one of the languages that forces parenthesized conditional expressions.]
This means most all of the SketchUp API instance methods. Ruby used to spit out warnings to
STDOUT when parenthesis were not used for method calls like this. But method calls may omit parenthesis if the method is global in class or module definition scope. Ie, the method is defined by [or mixed into]
Class. These methods have what is called “reserved word status”. The decision code for the warning slowed things down too much so it was removed.
So, generally when the receiver object is not the implied
self and must be stated before the method name using dot notation, then we should always use parenthesis around the parameters.)
Also, never put space(s) between the method name and the opening paren for the parameter list.
This is not yet reflected in the files pushed to GitHub.
Except that your bailout statement needs to be moved before the undo operation so that an operation is not opened in event of an empty selection.
Another thing you can do make your command context sensitive, so it can only be used when the selection is not empty. To do this add a validation proc to your
UI::Command object that checks for empty selection and returns
MF_GRAYED | MF_DISABLED when it is.
Sketchup.active_model.selection.empty? ? MF_GRAYED | MF_DISABLED : MF_ENABLED
The reason for the or’ed expression is the slightly different way menu items and buttons are handled on MacOS vs Windows.
You can get a bit fancier and actually test if the selection has groups, etc. …
ss = Sketchup.active_model.selection
if !ss.empty? && !ss.grep(Sketchup::Group).empty?
MF_GRAYED | MF_DISABLED
But try to keep proc evaluation to the minimum if used for toolbar button commands as they get called a lot.