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
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.
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ā¦
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
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.
@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ā¦