Delete an edge in Ruby without deleting its vertices?

Is it possible to delete an edge programmatically using Ruby but WITHOUT deleting the edges vertices, similar to this screenshot done “manually.”

This code appears to remove the vertices as well, messing up the faces generally

# create an inner edge collection
inner_edges_to_cull = []

# fill in the section plane from the section points
    # collect edges where each vertex has 3 or more connected edges and has 2 faces
    if e.end.edges.length > 2 && e.start.edges.length > 2 && e.faces.length > 1
        if !inner_edges_to_cull.include?(e)
            print "adding #{e} to inner_edges_to_cull\n"
            inner_edges_to_cull << e


print "inner_edges_to_cull: #{inner_edges_to_cull}\n\n"
Sketchup.active_model.active_entities.erase_entities inner_edges_to_cull

The vertices will be kept as long as any edge use them. If there is no edge using them, they will be purged. UI or Ruby API makes no difference.

1 Like

@eneroth3, maybe this is about the vertext/endpoint that ends up on two collinear edges without a third edge connected. The one on the left also gets purged after deleting the second edge in the animation.

Although I don’t know why you would want to keep that endpoint there. Unless it has to do with dimensioning your model in a certain way. Who knows? (OP does)

The workings of the SketchUp cleanup operation have, so far as I know, never been documented and remain somewhat inscrutable. @eneroth3 is correct that cleanup will detect when an erase leaves two co-linear edges and will merge them into one, deleting the vertex that previously separated them unless it is also used by some other entity. There is no documented way to avoid this cleanup action, so even though you might find a workaround that seems to work there is no guarantee it will always work.

only hiding the edge [e.hidden = true] will retain the integrity of all it’s original vertices…


That’s right! For some reason now its working so I must have been executing it wrong previously. Thanks!

I think the answer is not to answer the question as it was originally posed !
In the manual example you are erasing edges but their vertices are left behind, because those vertices are also used by other edges…

If what you really want to do is to erase those edges which support two [or more] faces, whilst leaving those edges which support only one edge [around faces’ perimeters], then the process is this…

# collect all edges which have >1 face [forget looking at the vertices !]
to_cull = ents.grep(Sketchup::Edge).find_all{|e| e.faces.length > 1 }
ents.erase_entities( to_cull ) if to_cull[0]

Note: if you also want to erase any ‘faceless’ edges, then change the find_all test to:

e.faces.length != 1
1 Like