Trying to create 2 seperate groups for boolean subtraction but the second group says deleted entity when I try to pushpull

Updated for correction: 6/30/2020

SKETCHUP_CONSOLE.clear
# Default code, use or delete...
model = Sketchup.active_model # Open model
entities = model.active_entities

# Add the group to the entities in the model
insulator = entities.add_group
insulator.name = "insulator"

# get group entities
ent = insulator.entities

# make some points
scale = 10.mm
top = 5.mm
pts = [[0,0,0],[scale,0,0],[scale,scale,0],[0,scale,0],[0,0,0]]

# add points to group
face = ent.add_face pts
if face.normal.z == -1
  face.reverse!
end
face.pushpull top

p insulator
# now the via
# Add the group to the entities in the model
via = entities.add_group
via.name = "via"
# get group entities
ent2 = via.entities

scale = 3.mm
centering = 3.mm
pts = [[centering,centering,top],[scale+centering,centering,top],[scale+centering,scale+centering,top],[centering,scale+centering,top],[centering,centering,top]]

face2 = ent2.add_face pts
p face2
if face2.normal.z == 1
  face2.reverse!
end
face2.pushpull 2.mm

via.subtract(insulator)

maybe your last line in your code should be:
via.subtract(insulator)

BTW:

Summary

the 5th line is make no sense (not used) here, but have to be like this if you want to use:

1 Like

Thanks, sorry I was using the default header in SketchUp Editor I just forgot to edit it. That seems to work but I guess I don’t really know what I am doing yet. I want to take the two groups and subtract one from the other but still have the other one going up like seen in the pictures. I can do this easily by hand but I want to do it via API.



The API’s boolean operations are destructive.

So you’ll need to make a copy the subtracted group before the boolean operation (if it is the only instance of the group’s definition. You need to do it this way because SketchUp will delete group definitions that have no instances.)

grp1_copy = grp1.parent.entities.add_instance(grp1.definition, grp1.transformation)
grp2.subtract(grp1)
# grp1 has been deleted
grp1 = grp1_copy # let the copy now be grp1
2 Likes

Thanks, that was very helpful.

1 Like