Group.to_component method is not working correctly

This is not an API method, but I believe refers to the example method I posted here …

That method does NOT return the group’s component definition, … it returns the group instance who’s name matches the 2nd argument.

(Again, a group is a special kind of component instance, who’s definition has the #group? flag set to true and is hidden from the “In Model” collection Component Inspector / Browser panel.)

You yourself prove that the returned object is a group instance by later calling grpDef.transformation upon it. The #transformation method is an instance method of the Sketchup::Group and Sketchup::ComponentInstance classes.
The Sketchup::ComponentDefinition class does not have a #transformation method.

This does NOT create a new component !

compDef = Sketchup.active_model.definitions["Dan"]
compDef.inspect
#=> nil

The Sketchup::DefinitionList#[] method is a lookup method only.

Use the Sketchup::DefinitionList#add factory method to create a new component definition in the model’s definitions collection.

You likely do not understand that Sketchup::Group#entities is an old “wrapper” method, that is shorthand for … group.definition.entities.

The API authors tried to mask the fact that a group was a component instance, and make it appear to act like a definition object. So they did not have a #defintion method defined for the Sketchup::Group for many versions until SketchUp v2015.

News Flash: Component Instances (and Groups) do not “own” an entities collection. Their definitions do.

So, … since v2015 you can just go ahead and call group.definition instead of the “clunkygroup.entities.parent call.


It is working just fine. You are confused is all. It looks better this way …

grpInst  = find_group_by_name(grpName)
compInst = grpInst.to_component
compInst.definition.name = compName # give new definition a better name
compInst.name = instName # give the new instance a better name