Intersection - Problem with coplanar cuts
-
I'm trying to put together a robust cut script but it turns out to be quite difficult. The attached .skp shows a problem with coplanar cuts that my script is unable to handle.
As seen in the .skp, it is possible to accomplish a proper cut manually with the following steps:
- Intersect the groups
- Make a group of the intersection edges (2 copies)
- Explode the intersection edges into both groups separately
- Merge the groups
However, I can't manage to perform these steps in a script (see Script Cut scene in the .skp). The problem is in step 3. The UI intersect method produces the face/face cuts as well as coplanar cuts. The API
intersect_with
gives only edges for face/face cuts. The script tries to get around this by adding all edges from group 1 to group 2, it then merges the geometry and finally deletes the stray edges. This doesn't work though, the problem is that the geometry just doesn't merge (it's probably too complex or something..)So, is there a (non-O(n^2)) way to get the same set of edges through the API as you get with the UI version of intersect, ie, a group of edges that includes coplanar cuts?
-
Have you tried Edge# find_faces on the collection of intersect edges.
@unknownuser said:
Edge.find_faces
The find_faces method is used to create all of the Faces that can be created with this edge. For example, if you use the API to draw three edges that form a triangle, the face between them will not show up because you've only drawn the edges, but if you call find_faces on one of the edges, the triangle will be filled in.
iedges.each {|e| e.find_faces }
-
The
.intersect_with()
method returns an array of the 'resultant edges', so as Dan says you could use
iedges = some_entities.intersect_with(.......)
and then
iedges.each{|e| e.find_faces }
In which entities context are you putting the 'resultant edges' ?Alternatively you could put the 'resultant edges' into a temporary group within the desired context, and then explode that group - the act of exploding it ought to auto-merge the edges/faces ?
-
Thanks for the replies. I think my original post was a bit unclear, the problem is quite subtle and it isn't a problem with intersect generally but rather:
-
Explode doesn't always merge geometry properly. In the image below an explosion will fail to cut the top face in the left model. The grouped edges in the right model is a subset, and in this case an explosion will split the top face into four faces as we expect. So, for explosion to be robust the geometry needs to be as simple as possible.
-
Intersect_with
doesn't provide all edges for coplanar cuts.
The original problem was a combination of 1 and 2.
If the two groups are cut from the UI, the resulting edges represents all coplanar cuts. So, what's the difference between the UI intersect and the API intersect? It turns out that the resultant edges from UI intersect is (conceptually):
intersect_with g0, g1 + intersect_with g1, g0
Thus, the solution is to make two calls to
intersect_with
in the API. The script below properly cuts the two pipes.` def mergeGroups(ent, g0, g1)
ng = ent.add_group
ng.entities.add_instance(g0.entities.parent, g0.transformation)
ng.entities.add_instance(g1.entities.parent, g1.transformation)
g0.erase!
g1.erase!
nt1 = ng.entities[0]
nt2 = ng.entities[1]
nt1.explode
nt2.explode
return ng
enddef intersect(ent, g0, g1)
eg = ent.add_group
g0.entities.intersect_with false, g0.transformation, eg , g1.transformation , true, g1
return eg
enddef cutGroupPair(ent, g0, g1)
ge0 = intersect(ent, g0, g1)
ge0.transform! g1.transformationge1 = intersect(ent, g1, g0)
ge1.transform! g0.transformationg00 = mergeGroups(ent, ge0, g0)
g11 = mergeGroups(ent, ge1, g1)ng = mergeGroups(ent, g11, g00)
return ng
end
mod = Sketchup.active_model
ent = mod.entities
sel = mod.selectioncutGroupPair(ent, sel[0], sel[1])`
-
-
You could try the first argument (recurse) of
.intersect_with()
method set as 'true'.
Also you can include more than one 'entity' in the method's final argument (entities2) - passed as an array of entities...
Say[g1, g2]
or even[g1.entities.to_a, g2.entities.to_a].flatten
Advertisement