Class: RuboCop::Cop::SketchupSuggestions::AddGroup

Inherits:
RuboCop::Cop show all
Includes:
RangeHelp
Defined in:
lib/rubocop/sketchup/cop/suggestions/add_group.rb

Overview

The idiomatic way to create groups via the Ruby API differ from the way you’d do it from the UI.

Using the API you should prefer to create the group first, then add your geometry into the group. This is more performant and predictable.

Grouping existing geometry via the API have historically been affected by bugs and issues.

If you do have to group existing geometry via the API, make sure you group geometry from the active context; ‘model.active_entities`. Otherwise you might run into unexpected issues, even crashes.

Examples:

Adding new geometry

# bad
face1 = model.active_entities.add_face(points1)
face2 = model.active_entities.add_face(points2)
group = model.active_entities.add_group([face1, face2])

# good
group = model.active_entities.add_group
face1 = group.entities.add_face(points1)
face2 = group.entities.add_face(points2)

Constant Summary collapse

MSG =
'Avoid creating groups out of existing entities.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



39
40
41
42
43
44
# File 'lib/rubocop/sketchup/cop/suggestions/add_group.rb', line 39

def on_send(node)
  return unless add_group?(node)
  return if node.arguments.empty?

  add_offense(node, location: arguments_range(node))
end