Inserting a group or component with Ruby API

Hello everyone
How can I, at this point of reading the code,
create a group or component…

Thank you very much for your help.

Joseph.

Pilastro_plu_prova.rb (1005 Bytes)

(1) A short piece of code (snippet) can be posted correctly in the forum.
(I’m not going to download such a small file and open it in my code editor.)

(2) A group of what ? All the entities you’ve created in the method ?
If so, then do not add them to the model’s entities collection. Instead create a group or a component definition, and then add the geometry to their entities collection.

from an example in the Sketchup::Group class documentation

# Add a group to the model.
group = Sketchup.active_model.entities.add_group
group.entities.add_line([0,0,0],[100,100,100])

You can also make a reference to the group’s entities collection object …

# Add a group to the model:
group = Sketchup.active_model.entities.add_group
# Reference it's entities collection:
ents1 = group.entities
enst1.add_line([0,0,0],[100,100,100])

Be sure to quickly add drawingelements or objects to the group’s entities or the SketchUp engine will delete the groups “out from under you”.

Many coders immediately put a cpoint at the group’s origin to prevent SketchUp from deleting the group. …

# Add a group to the model:
group = Sketchup.active_model.entities.add_group
# Reference it's entities collection:
ents1 = group.entities
# Add a guide point at the group's origin:
cpt = enst1.add_cpoint([0,0,0])

… then later after adding things to the group, they delete the guide point …

cpt.erase!

Mr. DanRathbun, thanks to the interest and willingness to give me advice,

Oops … yes, I mean all the entities created in the method up at that time …

I have not yet figured out how to create a group one … in this example the pillar …
create the group two … in this example the cylindrical hole …
subtract perhaps with the ‘subtract method (groap)’ the cylindrical hole (group two) from the pillar (one group) …

Mr. DanRathbun, I found in the forum of his advice given to “ChrisB89”
how to create different groups for certain entities included in the model,
groups to which you have to give a specific and different name and then perform the subtraction method …
I got this result, look at attached image …
Thanks for any other tips …

Joseph.

1 Like