Overwriting existing component with a group

I am wanting to rewrite an existing component with a group but keep the component intact.

model = Sketchup.active_model
ents = model.entities

group1 = ents.add_group
# add stuff to group1 #
group1.to_component

group2 = ents.add_group
# add stuff to group2 #

#### Overwrite group1 instance with group2 ##### 
or  
#### Add group2 to group1.definition then remove group1 instance #### 

Is there any way to do this?

Try …

group1.definition.entities.add_instance(group2.definition, group2.transformation)
group1.erase!

… and what will happen ? group1’s definition will no longer have any instances.

So when doing that from this I would do this?
I have a variable temp that stores group1.to_component.
I would like to overwrite the component or add to it and delete the existing instance.

group1.to_component
group1.definition.entities.add_instance(group2.definition, group2.transformation)
group1.erase!

I do not know what you mean by “that” ! Don’t assume we know what your goals are unless you tell us.

And so WHY ? What are using the reference temp for, and why do we need to know ?

The definition or the instance ? It is the definition that “owns” the entities collection that ALL of it’s instances use.

No problem. Add entities to the component definition’s entities collection.
ALL instances of the definition will be affected and show the additional entities.

I’ve shown how to delete an instance using erase!.

But if it is the only instance, then deleting it leaves the definition with 0 instances.

You use the term “overwrite”. There is no such term for API groups or components.
IF you mean replace a component instance with a group instance, it’s dead simple …

# After having created group2 and added entities ...
group2.transformation= comp1.transformation
comp1.erase!
# comp1's definition is still valid for creating other instances

Sorry, I was referring to the text below it with the this and that statement.

I have made a monster of a program but since you know a little about PCBs I can tell you what I am doing.

First I start with a substrate. Then I deposit 1 mm thick copper on top of that which I make into a component.

copper= group.to_component

At this point things get a little complicated because the etch depth could be less than the thickness of the copper layer.

First I have to copy the copper previous instance.

# Will be used to subtract from the copper definition
temp_subtractor = copper.definition.entities.add_instance(copper.definition, copper.transformation)

Then I use an etch mask to pattern into the copper using the subtract function

# Get the copper that needs to be removed
copper_to_be_removed = etch_mask.subtract(temp_subtractor)

Then Ideally, I would subtract that from the copper component. (although, this doesn’t work properly since subtract returns a group)

# remove the copper not in the mask.
copper = copper.subtract(copper_to_be_removed)

*EDIT: I forgot to answer one of your questions. The copper component is created in a separate function in the module but needs to be called and modified more than once.

I can create a standalone program so you can understand what I am dealing with if you would like.

If you look at this gif, you’ll see that one of the groups has been added to the component. But all the existing entities in the component still exist and I need them to be removed so that it looks like the second picture.


You cannot do this as it would be circular reference.
Ie, you cannot add an instance into it’s own definition’s entities.

@eneroth3 has some booelan coding tools that do not do the funky things the native tools do.


How thick is the copper ? SketchUp was designed to model buildings. It has an internal tolerance of 0.001" (one thousandth of an inch.) Trying to create very small edges and curves will often fail silently.
And you have to check the result of entity creation calls. Sometimes you get partial geometry creation with surfaces missing small faces.

If you an image mask, I suggest you just use that as a texture and apply it as a material to the PCB.

The other thing I would do if say my boss insisted on 3D circuit copper, is to get the traces as 2D faces (into a group) and then pushpull the top faces up some small amount.

Uh huh, it looked like it. (I used to be a precision resistor network chip designer for Solitron Devices back in the early 80s.)

SketchUp is not an application I would use for this kind of design. But I suppose if you draw at large scale it could overcome the issues. (Back in the day I’d layout chips at 200x by hand on mylar, and the Riviera Beach plant would cut the rubyliths from my layouts. Then they’d do the photoreduction then step and repeats onto glass masks for our group.)

Under no circumstances should you ever use global $vars. NONE.
I will not comment or make suggestions any any code that does.