I would like to nest componentinstance and new_instance within componentinstance2. This parent component could just as well be a group and not a component if that makes more sense.
Where did you get the “.new_instance” method from ?
In simple terms…
You have the truss_definition.
Make a new ‘container’ definition, into which you will place instances of the truss.
Iterate through the Y-spacings required.
Make a transformation [as a point], incrementing its Y value as needed.
Use:
container.entities.add-Instance(truss_definition, transformation)
Make a_transformation for where the container will be place.
Now use:
model.active_entities.add_instance(container, a_transformation)
Done.
Alternatively, a Group is just a special kind of Component definition.
You still add things to its entities-context.
You can change a Group into a Component-instance when you are done, you can get the definition from the instance if you need to…
Each time I create a new component instance I add it to the array with the second line of code and then at the very end I create the group using the array. I don’t know if this is the best way to do it but it actually works.
That is very fragile, assuming it’ll be at the end of the active_entities collection. When you use entities.add_instance it will return the instance entity - capturing this return value is a more reliable way to keep track your entities.
I now have a similar situation where I am trying to add a group to the array but the previous method does not work and what I have below is not working either:
When you pushpull a face, then afterwards that face no longer exists.
New side faces are added and two new main faces are added, one coplanar with the original and the other offset by the given distance, and reversed.
When you push [<<] the new_face2 into the array @all_trusses it’s not a valid thing. Sketchup.active_model.new_face2 is just weird - a Sketchup model has no method named .new_face2 ?
And anyway your new_face2 is not a valid? reference either as it no longer exists ?
Why not simply add group2 to the collection of trusses, as that is the ‘truss’ array?