Instead I would like to add my array of entitities “@all_trusses” to an existing group that has already been created and is essentially empty except for a small place holder entity in it to prevent it from being garbage collected.
you can create a group with entities as you already have done, create an instance of that group in the target drawing context (using Entities#add_instance) and then explode that instance. This is currently the only way to move/copy entities between drawing contexts using Ruby, not counting parsing and generating the geometry anew.
Beware that add_group called with an Array of entity objects doesn’t work when not in the active drawing context.
I have a pre-existing group. I would like to insert an array of entities (groups and/or components) into this pre-existing group. My thought was to first create a temporary group of the entities using my usual method above and then to insert this temp group into the existing group and then explode the temp group.
How is @all_trusses defined? I use the temporary group hack for loose or mixed geometry to not have to recreate it myself, but if it is all groups or components you can just use add_instance directly to place each new truss individually, without the temp group hack.
The way I have the plugin coded is that it collects up all of the misc. groups and components it creates and then adds them to the “maingroup” at the last step of the creation process, this seems to work fine for me.
The problem I am having with the code shown above is that the temp group is not landing in the same spot as the original geometry that I’ve deleted. Maybe my temptrans should just be 0,0,0 I will need to play with this some more.
When a groups is created with geometry in it from the start the origin is placed in the bounding box min corner, just as a user created a group. The identity transformation is not used.
After a number of iterations and reviewing the results I was able to surmise this was the case.
I’m wondering if I should use a component rather than a group for the main container of the truss assembly, maybe this will allow me better control of my origins and transformations.
Would there be any downsides to using a component instead of a group.
The alternative solution is to figure out how to position the temp group inside of the original group so that it all lands in the right spot. The joys (headaches) of creating a plugin…
Components stick in the In Model list of the component browser. I’ve used temp componenst very sparsely to get around the group garbage collection when there are no instances. However I’d recommend groups if possible for this.
Groups and components don’t differ in how axes can be controlled.
Read the transformation property of the group once it has been created. When placing a new instance of it, take this transformation into account.
I think I got it, a bit of a hack but it works. Your right you need to store the original origin point to make this work correctly, fortunately that does not change so I was able to pull it together and make it work.
Thank-you for allowing me to lean on your SketchUp knowledge and expertise. As I’ve said before I know enough to make me dangerous.