Assign IFC to group using Ruby

How can I assign IFC to group using ruby code?
(for example IFC 4 → IfcBeam)

In the documentation I saw the method ‘set_classification_value’ but it seems that it is only for components. Class: Sketchup::ComponentDefinition — SketchUp Ruby API Documentation

I saw that user can do that just by clicking here:

A group has a definition just as a component has a definition.

The definition method is used to retrieve the component definition for this group.
The IFC classification is assigned to the definition of the object.

Here is a small example where you first have to select a group, after which you can use this code immediately assigns the IFC4 classification “IfcBeam” to the selected object.

mod = Sketchup.active_model # Open model
sel = mod.selection # Current selection

group_definition = sel[0].definition 
group_definition.add_classification("IFC 4", "IfcBeam")

didn’t know that groups have also a component definition

It is working!

:thinking: Thinking loud: I did not tried, but…perhaps:

You may need to apply .make_unique method on a selected group before classifying. Otherwise an “unmodified” copy of the group will get the same classification, witch, maybe, could not be your intention…


The Group #make_unique method is used to force a group to have a unique definition. If the group is already unique in the model, nothing happens.

Copying a group in SketchUp will create a group that shares the same definition. SketchUp implicitly makes group unique when edited from the GUI, and from a user point of view groups could be thought of as always being unique. To honor this behavior, call this method before editing a group through the API.