Erase faces created after intersect_with

hello everyone,
i used intersect_with on a model to create the intersections between 2 faces or more, but now i need to delete the extra faces created after the intersection to get a clean roof.
i tried to get the faces array before and after intersection, make the difference between them and get the new faces created, but instead of the deleting the faces i want it erases the faces below them, as in the picture below, instead of having the A model as a result i get the B model.
how can i return the new faces above to get the A model as a result ?
thnx
thatā€™s the code i used:

model = Sketchup.active_model
entities = model.entities
fc=entities.grep(Sketchup::Face).to_a #get all faces before intersection

                     recurse = false 
                     hidden = true
                     model.entities.intersect_with(
                        recurse,
                        IDENTITY, # Transformation for the calling Sketchup::Entities
                        model.entities, # parent (target) Sketchup::Entities
                        IDENTITY, # parent (target) transform
                        hidden,
                        model.entities.to_a # Entities to intersect the calling Sketchup::Entities with
                      )
 fc2=entities.grep(Sketchup::Face).to_a     #get all faces after intersection
 
 
fc.each do |del|
    fc2.delete_at(fc2.index(del).to_i) #delete the faces before intersection from the faces arry after intersection to get the new faces ceated
end
UI.messagebox("fc2 length #{fc2.size}") 
entities.erase_entities (fc2) #delete the ne faces created

roof intersection.skp (257.8 KB)

I am not where I can check this, but I suspect the bug is that you are assuming that the faces you found before the intersection will be the portions below the ridge after the intersection. Your image B plainly shows this isnā€™t what is happening. During operations that intersect faces (Including situations where you just add another face that overlaps an existing one) SketchUp makes no promise that it will retain the pre-existing faces or use them for a particular part of the after-intersection geometry. You need a better test, e.g. in your specific example, which faces are higher in z.

yes i tried the which face has higher z but it doesnā€™t work in cases like the image below, i managed to get the edges added after intersection how can i using this edge get the faces that i need to delete ?
i need to delete the faces A B and C and i managed to get the two edges with the red lines in the picture.

That geometry is more complicated than your first post and will need a more complicated test. Iā€™m not where I can do anything just now, but unless someone else solves it Iā€™ll get back later.

1 Like

oky thank you so much yes iā€™ve been working on it for the past 2 days and i canā€™t seem to find a solution for more complicated models if you or anyone could help it will be great.
thnx again

At the risk of ā€˜boiling our cabbages twiceā€™ā€¦
In a parallel thread I told you to look at my Roof.rb codeā€¦
Around lines in the late 400s and 500s there is some code that might helpā€¦
But the way you are initially making your faces is not helping you later onā€¦
It is not a simple task to trap for all permutations of a set of intersecting roof planes, and erase just those that are easy to see as being ā€˜unwantedā€™ā€¦

But consider how you know whatā€™s to go, and try and write some code to mimic thatā€¦

Group your new geometry so you only need to intersect and search in the groupā€™s entitiesā€¦

After the intersection, any face that is wholly above the Z level you sprang the origin faces from is probably one to be erased [C in screenshot copy, ā€˜blueā€™ X] - then you search for edges with no faces and erase thoseā€¦
Any face that is at the Z level but has a horizontal edge at the same level as the original face [like A, ā€˜redā€™ X] is also a candidate for erasureā€¦
If you have been keeping a collection of ā€˜upperā€™ horizontal edges used by the original faces - start/end positions and also lines/vectors etc then you can also spot others needing erasing like B - ā€˜magentaā€™ X.
You can delete an edge and its face goes - then delete other unfaced edges that result, or first delete the face and then the unfaced edges that resultā€¦

1 Like

thank you for your answer, yes i tried the test on the z value but it doesnā€™t work in some complex cases, what iā€™m trying to do now is find the center of each edge created after intersection (ones with red line on them) and get the center of each face and use > pt1.vector_to( pt2) between the center of the edge and the center of the face and then delete the face that led to a vector pt1,pt2 with a positive z coordinate.
iā€™m about to test it and see if it works.

The horizontal top edge of every face plane you add has a unique ā€˜lineā€™ - face.line - which is an array of a point and a vector.
If you collect those in an array as you add the faces you have a useful crib.
Then intersect all.
There will be faces with a top horizontal edges that have a ā€˜lineā€™ equivalent to one the remembered array [lines].
Collect all edges in the context.

edges.each{|edge|
  lines.each{|line|
    if edge.start.position.on_line?(line) && (edge.line[1]==line[1] || edge.line[1]==line[1].reverse)
      edge.erase!
      break
    end
  }
}

Then recollect the remaining edges and erase unfaced ones

edges.each{|edge| edge.erase! unless edge.faces[0] }

This should get you some way towards a solution ?

1 Like

iā€™ll try your idea and get back to you with the result, as the vector between the intersection line and the face center caused a problem with finding the center of a face

Hi, i know this is an old post, but i am facing a similar situation, i managed to create my geometry, make a plane, intersect that plane with my geometry, now how can i erase the initial plane, and the faces after the plane, i tried bounding the group and erase everything thats not in bound but the bound includes everything, now i got 3 faces meaning i have 3 outerloops? can i choose 2 of those en erase? any ideas? thank youMetal Roof.rb (7.4 KB)

You erase the cutting plane by saving its identity when it is created,@cp = ent.add_face(pts),
then erasing itsā€™ edges which will erase the face as well, entities.erase_entities(@cp.edges).

The ā€˜extraā€™ face is created because your code creating the side_edges starts with the -1,0 indexes which means the first and last points are paired. Adding next if j==0 fixes this problem.

Erase the part ā€œbeyondā€ the cutting plane by comparing the cutting planes x coordinate with the edges bounds.center.x and erasing it if is greater.

I took a completely different approach and eliminated the need for a ā€˜cutting planeā€™ā€¦

by adding c_points to an empty group you can use the group boundsā€¦

while group.bounds.width <= base
  # some conditionals... then
  gents.add_cpoint(pt)
end

those point are then the basis of ones taken forward toā€¦

if group.bounds.width != base.to_l
   pt_lst = gents.to_a.last.position.to_a
   pt     = [base, pt_lst[1], pt_lst[2]]
   gents.erase_entities(gents.to_a[-1])
   gents.add_cpoint(pt)
end

I also generated a sine wave, so I could try different LOD [levels of detail] i.e. number of segmentsā€¦

the top is actually less the @nicolas.pojmaevichā€™s 26, but even 4 [the lowest panel] looks okā€¦

although they are all exactly base width, my code for clipping sometime produces a fold???

this happens with some combinations of corrugation pitch and number of segmentsā€¦
I canā€™t fathom whyā€¦

Iā€™ll PM the code if anyone wants to play, but it needs a new topic to discuss furtherā€¦

john

@john_drivenupthewall, it seems the machine beat you on this one, what if you add a temp line to the bottom points? that line intersect with the wave an cuts it giving you that exact final point, youā€™ll need an extra element thouā€¦and clean upā€¦

@sdmitch, can you share the code? i wanna see it, im learning over hereā€¦

for now, xmas is longā€¦

I sorted out the sine wave, to better match yours, but then I broke something elseā€¦

john

broke away johnā€¦:slight_smile:, im learning html over hereā€¦ they dont recommend tables for html layout, instead header/section/footerā€¦ok