You are muddling up ‘definition’ and ‘instance’.
A component definition [i.e. what is shown in the Components Browser model-tab list] can have instances placed in the model or within other containers in the model - like groups - or even within other component definitions in the model [it could also have 0 instances]. definition.instances returns an array of that definition’s instances instance.definition returns the definition to which that instance is linked
You can also set an instance to be linked to another definition… e.g. instance.defintion=some_other_definition
Because a definition can have multiple instances editing one instance changes all other instances.
The ‘make_unique’ tool splits specific instances off from their parent definition so changing one of those instances does not affect its previously connected siblings.
An instance can have a name different from its definition’s name.
A group is simply a special kind of instance of a definition.
Groups are not displayed in the Components Browser and if you delete a group its definition is gone - unlike deleting an component’s instance which would leave its now unused definition in the Components Browser.
You can copy a group so that there are more than one in the model, but editing one of those automatically makes it unique and separates it from its sibling[s].
A group can have a name different from its definition’s name [which remains hidden].
The group.to_component method works on a group, NOT on its definition.
It returns a component-instance - i.e. its definition is now displayed in the Components Browser
The definition is named after the group - e.g “Group#5” - unlike the context-menu equivalent tool which asks the user for a definition name - so you’ll probably want to rename it just after it’s been created?
Incidentally Images are also another special kind of instance of a definition...
Some background information.
I am developing a parametric modelling system in SU Pro.
(It can create arbitary objects and place luminaire 3D models at the exact location and orientation)
It is based on the roo plugin.
So an excel table is parsed by my ruby script.
Due to excel table properties every object (component or group ) MUST be referenced by name.
As far as possible components are used and later transformed to the exact location.
Recently it was found that groups should be used too.
Whenever a hole to be cut and/or openings should be made on walls; groups should be used.
When a complex object (group) is created following the a/m logic the group is to be converted into component.
This newly created component is to be placed at several positions.
When the .to_component method was used something very strange happened.
The new component could not be accessed by the ruby script however it was clearly visible in the SU GUI.
If this new component was moved in the GUI then the ruby script could find it by name.
The second code sniplet does exactly what is needed.
compDef=Sketchup.active_model.definitions[compName] # create new component
Convert the group into a component which can be found by name (and erase the unnecessary group definition)
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 “clunky” group.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