The last line of this short block of code is causing SketchUp to bugsplat… I can’t figure out why. I’m just taking a bunch of entities that were exploded from a previous component and trying to create a new group within my main wall group.
When I comment out the last line of code, the method shown works exactly as expected. The entities of the component are positioned within my main wall group per the origin of this group as I would expect.
When the last line is enabled a ghost copy of the entities appears to be dropped at the origin of the main group and then the switchmaingroup is created outside of the main wall group. Then it eventually bugsplats. I seem to have hit upon something that is not allowed, but I’m not sure why.
I only use components for things that I know to be identical by definitions. If I ever edit objects on individual bases, e.g. a beam being cut to fit at one specific place in the building, I prefer it to be a group. This both prevents it from showing in the component browser, and clearly tells this is a unique part, typically made on the construction site.
I see, when doing the same from code: Modifying a copy of a component to be a unique part.
.to_group would be somewhat equivalent to instance.make_unique followed by instance.definition.hidden = true (on the new definition). Although I am not sure if this hidden= (inherited from Drawingelement) has been overriden to correspond to hidden? (ComponentDefinition visibility in components browser).
To hide a component from the component browser I think you have to set an attribute in the Dynamic Component directory. However it would still be a component and if new copies were made editing one would affect all.
You’ve hit the nail on the head with this one. As much as would love for all of these switches to remain as components it doesn’t really work. Each one can have a number of unique properties (ie. faceplate and switch may have unique material applied). I basically start with a base geometry (the component) then bring it in, convert it to a group and then begin modifying it. Based on this workflow groups make more sense.
@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.
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.)
I can see there has been plenty of discussion regarding this issue and plenty of suggestions from SU minds that are far superior to mine but I don’t really see a clear path forward.
The component instance that I am exploding contains three groups (each is a solid). I would like to retain layer and material information if possible, however I can always re-assign those properties if required. I have not attribute libraries or meta data with these three groups other than the group/instance name.
I tried Aeriluis’s method of assigning the component instance to a group and then exploding the component inside the new group but this bugsplats as well. (See my second code block in this thread).
The key take away from this discussion seems to be that you want to create an empty group first then add your component instance into it, then explode the component instance. It all seems so simple now.