How can I use the ruby API to programatically create a manifold from this group

The skp attached contains the desired goal and the problem. The problem is created programatically via a followme function and will be part of a program I am designing that will create 3D layouts of semiconductor devices. Therefore, I can’t just do an add_line in there and delete the faces. The deleting of the faces I can do it’s adding the line at the intersect of the faces that I can’t figure out.
example.skp (76.5 KB)

There is no annotation in the model to describe what is what and the problem.

I see 2 upside down pyramids.

We ask that you provide a snippet of what you have tried at least … (and of course that you at least try.) :wink:

How are you determining the vertices of this pyramid ? It might not be a solution for followme.

Perhaps draw a flat view (as if looking down from above, or looking up from below) with the x edges meeting the short edge. Then transform the vertices of that short edge upwards (or downwards) parallel to the Z_AXIS to create the top surfaces of the pyramid.
Lastly do a find_faces call on one of the base edges to close the pyramid making it manifold.

Sorry, the skp is labeled in the outliner. I was just working on the script to get it started, I have been using the console+ to try things out so far.

The followme function creates the pyramid seen and I can’t really change that part. What I can do is manipulate the pyramid after it has been created.

I tried to use find faces, it didn’t work because where the faces intersect there is no line.

This is the issue here.


This is what I am going for.

Solved it. For some reason this didn’t work before but it does now.

# standard inclusions
model = Sketchup.active_model
ents = model.entities

# get the groups
groups = ents.grep(Sketchup::Group)

# get group of interest (for this skp it is the first one)
goi = group.first

# intersect faces within the group with each other.
def intersect_faces_within_group(group)
  # get the group entities
  g_ents = group.entities
  
  # new empty transformation
  tr = Geom::Transformation.new()
  
  # create our intersection
  g_ents.intersect_with( false, tr, g_ents, tr, true, g_ents.to_a)
  
  # group edges
  g_edges = g_ents.grep(Sketchup::Edge)
  
  # delete any edges that don't touch more than 1 face.
  g_edges.each{ |e| e.erase! if e.faces.length < 2}
end

intersect_faces_within_group(goi)

example.skp (76.5 KB)

1 Like

That is weird. Intersecting a group’s entities with itself and putting the result inside the group.

I would have thought the both transformation arguments should be tr = group.transformation.


Another possibility might be to identify the overlapping faces and intersect the planes.

iline = Geom::intersect_plane_plane( face1.plane, face2.plane )

And then get the points where the edges (of one of the faces) cross the line …

pts = face1.edges.map {|edge| Geom::intersect_line_line(edge.line, iline) }
pts.compact! # remove the 1 nil for the bottom edge.
group.entities.add_edge(*pts)

However it might be necessary to transform the points depending upon what editing context the model.active_entities is at the time (before adding the new edge.)

1 Like

I think the method I outlined works a little better for my situation because the object may not always be a square pyramid. But, in a situation as you describe your method does seem like a good option. I would say, however, my method may be more effective for someone doing a roof using the followme tool in ruby API to remove overlapping parts you don’t want.