[Code] Add "Make Group Unique" to popup context menu

Add “Make Group Unique” to popup context menu.

make_group_unique_popup_menu_item.rb (558 Bytes)

# encoding: UTF-8
#
# Adds "Make Group Unique" to popup context menu.
  
require 'sketchup.rb'
  
if !file_loaded?(__FILE__)
  
  UI.add_context_menu_handler do |popup|
  
    if Sketchup.active_model.selection.length == 1
      mod = Sketchup.active_model
      sel = mod.selection
      if sel[0].is_a?(Sketchup::Group)
        popup.add_item("Make Group Unique") {
          mod.start_operation("Make Group Unique",true)
            sel[0].make_unique
          mod.commit_operation
        }
      end
    end
    
  end
  
  file_loaded(__FILE__)
  
end
1 Like

This do more than what is needed in this case - it looks for selected curves etc.
if !Sketchup.active_model.selection.length == 1 at the beginning would save you from checking the selection size again.

1 Like

Oh yea, this makes sense. I’ll update the example later today.

EDIT: Done. Although the test did not need negation.