# A bug in the Group and ComponentDefinition stats

**URL:** <https://forums.sketchup.com/t/a-bug-in-the-group-and-componentdefinition-stats/84730>\
**Category:** Ruby API\
**Created:** [January 5, 2019, 8:17am UTC](https://forums.sketchup.com/t/a-bug-in-the-group-and-componentdefinition-stats/84730 "2019-01-05T08:17:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saedrna](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/saedrna/32/8717_2.png) [@saedrna](https://forums.sketchup.com/u/saedrna)\
**Post date:** [January 5, 2019, 8:17am UTC](https://forums.sketchup.com/t/a-bug-in-the-group-and-componentdefinition-stats/84730/1 "2019-01-05T08:17:13Z")

</div>

Hi,

When copy a group, just after the copy operation is done, without going into the copied group, the componentDefinition of the group has two instances, the original and the copied. I don’t think this is the expected behavior for groups.  
And after going into the copied group (by double click), the coponentdefinition refreshed to only one instance.

For the groups below,

 ![1](https://global.discourse-cdn.com/sketchup/original/3X/8/e/8e2a67ea8ab87729392ebd432b7bdaf6c757eb4e.png)

Now it gives

```auto
g0 = group
#<Sketchup::Group:0x00024afc956250>
g1=group1
#<Sketchup::Group:0x00024afc9545b8>

g1.definition.count_instances
2
g1.definition
#<Sketchup::ComponentDefinition:0x00024afc9562c8>
g0.definition
#<Sketchup::ComponentDefinition:0x00024afc9562c8>

```

And after going into the copied groups for once, it gives

```auto
g1.definition
#<Sketchup::ComponentDefinition:0x00024afc9562c8>
g0.definition
#<Sketchup::ComponentDefinition:0x00024afc935b18>
g1.definition.instances
[#<Sketchup::Group:0x00024afc9545b8>]

```

Is this a bug or expected behavior?

Han

---

<div class="post-metadata">

**Author:** ![Aerilius](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Aerilius](https://forums.sketchup.com/u/Aerilius)\
**Post date:** [January 5, 2019, 9:33am UTC](https://forums.sketchup.com/t/a-bug-in-the-group-and-componentdefinition-stats/84730/2 "2019-01-05T09:33:36Z")

</div>

> [@saedrna](#):
>
> Is this a bug or expected behavior?

This is expected.

Groups are good for keeping objects together (grouping them) and if you do not intend to reuse them.

This is why groups are components with special behavior added:

- do not display in the components browser (to avoid clutter)
- changes to an instance do not propagate to all other instances, but the current instance is made unique (without _right-clicking → Make unique_)

One could argue whether a copied group should immediately have an independent definition (which takes extra space) or only once it is being modified.

---

<div class="post-metadata">

**Author:** ![saedrna](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/saedrna/32/8717_2.png) [@saedrna](https://forums.sketchup.com/u/saedrna)\
**Post date:** [January 8, 2019, 3:22am UTC](https://forums.sketchup.com/t/a-bug-in-the-group-and-componentdefinition-stats/84730/3 "2019-01-08T03:22:52Z")

</div>

Thanks, I have looked at the doc of `Group::make_unique` and it says,

```auto
Copying a group using the copy tool in SketchUp will create copies of the group that share a common definition until an instance is edited manually or this method is used. If multiple copies are made, all copies share a definition until all copies are edited manually, or all copies have this method used on them. This method ensures that the group uses a unique definition entry in the drawing database.

```

I think this is what I have encountered.

---

<div class="post-metadata">

**Author:** ![eneroth3](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/eneroth3/32/1222_2.png) [@eneroth3](https://forums.sketchup.com/u/eneroth3)\
**Post date:** [January 8, 2019, 9:38am UTC](https://forums.sketchup.com/t/a-bug-in-the-group-and-componentdefinition-stats/84730/4 "2019-01-08T09:38:19Z")

</div>

This is by design, as it would be a waste of space to have duplicated definitions for identical groups. Also it can be very nice when modeling, as you get an extra chance to convert groups to components even after having copied them (e.g. using TT’s selection toys).

For a plugin you can call the make\_unique method before editing a group. I think it’s best practice to do this silently on groups as the user expect editing one of them to only affect that one. For components you should generally avoid make\_unique as the user expect changes to one to apply to them all, but if you need to edit them individually (e.g. to [line up their axes with the parent](https://github.com/Eneroth3/line-up-axes)) I’d recommend to warn the user and give them a chance to cancel the operation. Otherwise there is a risk the user notices they were made unique way later, and have done too much work in between to be able to simply undo the change.
