How do I copy a face with Ruby?

Please forgive a total beginner’s question:
I see how to copy a group but I don’t a method to copy a face or any other entity.
How can I do that?
Huck

There is no methods to do so. One hacky workaround would be to group the face and copy the group around then explode. But you might as well just recreate the face, reading the outer and inner loops of the face you copy.

Is the problem the same for components? I don’t see a method for that either. How can I copy a component?

Each component has a definition.
To add an instance of a component… use:
entities.add_instance(definition, transformation)
The entities determines its context [aka its ‘container’ - e.g. model.entities, group.entities, definition.entities].
The transformation sets where it is placed, how it is rotated/scaled etc… [Geom::Transformation…]

There are several ways to get a reference to a definition
defn = model.selection[0].definition if it’s a component_instance
or
defn = model.definitions[‘some_name’] if you know its name
or
defn = model.definitions[-1] if it’s the last added definition
or
defn = some_instance.definitions if you have a reference to a component_instance
or
defn = group.entities.parent if you have a reference to a group
etc

Thanks a lot.

I will take some time to absorb all this and put it to use.

How could I copied a component instance after it was scaled?

DanRathbun advised me to use the method
“mod = Sketchup.active_model
def1 = mod.selection[0].definition
copy = mod.entities.add_instance( def1, IDENTITY )”
But when I tried this method, I could only get the denfintion.

Could you help me with that?

A straight forward approach would be to use the transformation of the original instance instead of IDENTITY. This will place the copied instance in the same location, but it can be easily moved with a subsequent transformation.

Except that he specifically asked to have the copy untransformed and placed at the model origin.
(His issues come from not correctly entering or pasting code into the console, and not first learning the basics of Ruby. Ie, given an example method, he did not paste the entire method into the console, he attempted to type it in line-by-line.)

ref topic: How to create a component with existing entities in a component by ruby?

I finally just gave him a non-method context-menu command example: