Normally I add a group of entities (groups and components in an array) to my large assembly group with this single line of code:
@maingroup = Sketchup.active_model.entities.add_group(@all_trusses)
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.
Seems I can’t easily do this. Can I then somehow copy or insert a group into an existing group?
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.
EDIT: Issue with add_group in inactive drawing context: https://github.com/SketchUp/api-issue-tracker/issues/42
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.
Does this seem reasonable?
What is the purpose of the temporary group?
This seems to work but I’ve got to look at my transformations a bit and make sure I’ve got it right:
@tempmaingroup = Sketchup.active_model.entities.add_group(@all_trusses)
temptrans = @tempmaingroup.transformation
tempdef = @tempmaingroup.definition
tempinstance = @maingroup.entities.add_instance tempdef, temptrans
erasestatus = @tempmaingroup.erase!
No purpose other than to get the array of entities into a container that I can then work with.
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.
P.S.: That does not seem to fix the problem.
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.
According to the API docs, if we set a definition’s hidden attribute to
true, then it will be hidden from the “In Model” collection.
#hidden= method seems to have no effect !
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.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.