# To\_group Method?

**URL:** <https://forums.sketchup.com/t/to-group-method/86465>\
**Category:** Ruby API\
**Created:** [January 29, 2019, 5:22am UTC](https://forums.sketchup.com/t/to-group-method/86465 "2019-01-29T05:22:54Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [January 29, 2019, 4:19pm UTC](https://forums.sketchup.com/t/to-group-method/86465/12 "2019-01-29T16:19:04Z")

</div>

> [@medeek](#):
>
> I would like to quickly and easily convert a component to a group. Unfortunately, there does not seem to be an appropriate method for this.

Correct. We’ve discussed this and asked for such an API method years ago.

This was from October of 2016 …

> [@Convert component to group](https://forums.sketchup.com/t/convert-component-to-group/32304/19):
>
> Yes it would be so much simpler if the API had a **`to_group()`** instance method of the **`ComponentDefinition`** class, that would convert it to a group definition without all this rigmarole and exploding. All the definition’s instances then would become group instances, and there’d be no need to copy attribute dictionaries and native properties.

@thomthom, can you confirm if it’s been logged internally ?

> [@medeek](#):
>
> Is the appropriate workaround to simply explode the component instance and then collect up the entities and utilize the `add_group` method?

No, … because …

> [@medeek](#):
>
> The last line of this short block of code is causing SketchUp to bugsplat… I can’t figure out why.

- [Entities.add\_group causes Bugsplat!](https://forums.sketchup.com/t/entities-add-group-causes-bugsplat/31160)

@Aerilius, describes the simplest and safest pattern if the instance has no attribute dictionaries, you want to discard any attribute dictionaries and you care not for any of the instance’s properties (ie, material, hidden, layer settings, etc.)

We’ve posted Ruby workarounds several times. I remember @TIG posting a really good example that copied the properties and then all the instance’s attribute dictionaries over to the new group instance.

> [@Aerilius](#):
>
> Although I am not sure if this `hidden=` (inherited from `Drawingelement` ) has been overriden to correspond to [`hidden?`](http://ruby.sketchup.com/Sketchup/ComponentDefinition.html#hidden%3F-instance_method) ( `ComponentDefinition` visibility in components browser).

I think that the `hidden=` was bugged in this regard, if I remember correctly.  
That then makes the purpose of the `#hidden?` method kind of moot.

I asked about the hidden flag in the following Issue for the C API, but got no response then.  
The issue is still open, as “Needs Information” and has not been fully processed (ie, logged internally.)

> <https://github.com/SketchUp/api-issue-tracker/issues/51#issuecomment-365737423>
>
> Currently, there is a way to create a ComponentInstance from a ComponentDefiniti…on. There is no way to create a Group from a ComponentDefinition (the group type). This is despite the fact that a Group is a derived class of ComponentInstance in the C API.
> 
> This shortcoming prevents more than one copy of a group from being created through the C API; each group must be unique. This has an impact on performance for a program that uses the C API, and the size of the output file if many copies of Groups must be created.
> 
> There is some discussion on the forums: https://forums.sketchup.com/t/sugroupref-confusion-in-the-c-api/36236
> 
> I propose this new function be added to the ComponentDefinition class:
> \`\`\`
> /\*\*
> @brief Create a group from a component definition.
> @param\[in\] comp\_def The component definition object.
> @param\[out\] group The group created.
> return
> \- \\ref SU\_ERROR\_NONE on success
> \- \\ref SU\_ERROR\_INVALID\_INPUT if comp\_def is invalid
> \- \\ref SU\_ERROR\_NULL\_POINTER\_OUTPUT if group is NULL
> \- \\ref SU\_ERROR\_GENERIC if comp\_def is not the definition of a type that can be
> made into a group
> \*/
> SU\_RESULT SUComponentDefinitionCreateGroup(
> SUComponentDefinitionRef comp\_def,
> SUGroupRef\* group);
> \`\`\`

---

_[View the full topic](https://forums.sketchup.com/t/to-group-method/86465)._
