Removing the collided or intersecting breps from a brep list

Hi all,
I have a list of Breps, I am trying to delete the colliding Breps in my list. I have tried to input my list and choose every 2 items and test their collision, if the test result is TRUE, one or both items should be deleted (not sur yet if I delete both or keep one).
Unfortunately I get the python error : ‘Guid’ object is not iterable
kindly find attached my files , where the python script with error is labeled in a group called ‘‘problem’’.
my python script :
mport rhinoscriptsyntax as rs

newb =

for i, b in x:
if rs.IntersectBreps(i, b) == True :
rs.RemoveObjectFromGroup (b, x)
newb.append(i)we (32.6 KB)
newb.append(i, b)
#return i, b
print newb
Thanks all in advancewe ba3den.3dm (2.2 MB)

HI @Kareem,

One problem is that you provide a tree to the x input, which makes the GHPython component run for each tree branch separately. Since, you have only one item/brep per branch, there really is nothing to compare to for the single brep. You either need to flatten the x input, or if you want to keep the tree structure, provide a tree with at least two items per branch.

Furthermore, for i, b in x doesn’t fly! For this work, x would have to be a nested list, with at least two items in each sublist (e.g. [ [b0,b1], [b2,b3], …, [bx,by] ]). What you have is a flat list (e.g. [ b0, b1, b2, …, bx ])
If I understand correctly, you want to evaluate each brep with the next brep in the list or tree branch x.

for i in range(len(x)-1):
    print rs.IntersectBreps(x[i], x[i+1])

You have to subtract 1 from the length of the list or tree branch x, since the last brep in the list has no next brep to possibly intersect with.

Now, if you look at what is printed, you’ll notice that your if statement doesn’t work either. rs.IntersectBreps(x[i], x[i+1]) doesn’t return a boolean (e.g. True, False), but a list of intersection objects, curves or points, on success, or None on error or failure (cf. Reference).
In order to check if two breps intersect, you simply have to verify whether rs.IntersectBreps(x[i], x[i+1]) is not None.

for i in range(len(x)-1):
    if rs.IntersectBreps(x[i], x[i+1]) != None:
        print "Yeah, they intersect!"
1 Like

Hi Mr.@ p1r4t3b0y , Thanks very much for your response.
I tried actually to gather all the breps on the edges of my lists as in photo to make it easier, and I tried to apply this :
import rhinoscriptsyntax as rs

newb =

for i in range(len(x)-1):
if rs.IntersectBreps(x[i], x[i+1]) != None :
print newb
a = ghdoc.Objects.Geometries
unfortunatley my ‘‘newb’’ output list is empty !! although there is some non intersecting hexagons as you see in the pic.

kindly find my gh file attached.

we (30.8 KB)

I’m currently not on my computer, but judging from your screenshots above, it seems that you’re not really outputting your newb list!
You have two possibilities: either rename the component output a to “newb”, or pass newb to the variable a inside the script.
I don’t understand why you pass ghdoc.Objects.Geometries to a. That doesn’t really make sense.

1 Like

I am sorry for any inconvenience, take your time to respond . I actually followed your last correction but it gave me in the output the same number of breps I have entered which is 121 !! . again no hurry and thanks alot !

It might be the case that at each iteration/step, the current brep is intersecting the next one, which would then mean that all breps are in fact intersecting, and no brep would be sorted out. :slight_smile:
If I remember correctly all your breps are adjacent hexagonal cells. Please note, that even breps that are only touching each other in a single point are intersecting. Maybe you need a more precise strategy? What is your ultimate goal?

My goal was to group the intersecting ones in a group and the non intersecting ones at another group, as you see in the picture some hexagons are on the edges, and they don’t collide with any other ones. Also the code I tried to use after you cleared me the errors is :
for i in range(len(x)-1):
if rs.IntersectBreps(x[i], x[i+1]) != None:
so it should here append the non intersecting ones …

Just spotted that one: See attached (but you can’t auto translate C to P). Other than that the “ideal” approach is rather way more complex than the solution attached (requires ccx clustering and THEN attempting to locate the isolated items - that way you can achive max density etc etc).

Brep_IsolateCcx_EntryLevel_V1.3dm (360.1 KB) (129.1 KB)

Some hints:

  1. Do a double Loop - see ComputeCcx Method - and get the CCX status in a bool[ , ] Array. (Note that the C# attached works either with Meshes [fast] or Breps [slow]).

  2. In order to visualize the events I’ve added a Matrix as well.

  3. Having the Array - a kind of Adjacency matrix so to speak - on hand try to translate to P that one:

1 Like

BTW: Here’s why this issue of yours (the general case) is more challenging from what you think on first sight: Spot the elimination combos in these 2 clusters (ccx islands) - meaning that depending on the local cluster Topology … some additional rules are required in order to eliminate the minimum amount of items (yielding a cluster with max density):

This obvioulsy happens when we have closed ccx cirquits on a per cluster basis (i.e. as in the left cluster that could yield 4 items instead of 3).

1 Like

Really thanks alot !