GH Python - Intersect List of Surfaces in Rhino.Geometry

Hi
I have a list of UnTrimmed Surfaces which are a part of a Pyramid Geometry, I want to extract the intersections for all of the surfaces and trim all the extra parts except “Solid Difference” parts.
in another way, at the end I want to have Some surfaces like the picture below:

I know in Rhino, I can Use the “Intersect” Command simply and trim or split the surfaces with the curves extracted from that command. But in ghpython in Grasshopper, I can’t figure it out!
I wrote some script for that but the output is null and I don’t know whats wrong with it. I wonder if someone can solve the issue.
thanks.


intersect command in rhino.3dm (198.9 KB)

SurfaceList Intersections.gh (39.8 KB)

Hi @alirahi32

Have you tried setting the input type as Brep?
You can use the Brep.CreateBooleanIntersection() method to create a 3D Solid Intersection.

1 Like

Try to translate this (C#) to P

result:

2 Likes

It gives me an array of Breps and I can’t extract the data from python script into the grasshopper!


rhinogeometrybrep.gh (15.2 KB)

I’m not sure if I’m doing this right but I’ve managed to write this code on python:
Trim Brep
Trim Brep.gh (13.8 KB)
now the problem is that I want the Other part of the Brep in the output of my code but instead, I Get another(Green part of the surface in picture below)!

Here is a Python script based on the C# from @PeterFotiadis
SurfaceList Intersections_v2.gh (39.7 KB)

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import Rhino

tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance
a = []

for i in x:
    for j in x:
        if j == i: continue
        trmd = i.Trim(j, tol)
        if trmd!=None and len(trmd)>0:
            i = trmd[0]
    a.append(i)

intersections = a
1 Like

thank you!
Can you please tell me what is the rull of this line of Code?
thanks

tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance

Its just taking the same tolerance settings as the Active Document. You could manually set it to 0.01 ( as you had in your original script), if you like.

1 Like

thanks a lot.

If you convert - where possible - the Breps to Solids (CapPlanarHoles(tol)) then using bool diff (instead of Trim) we get this result:

So you need the non planar BrepFaces (not derived from the OEM BrepFace) shown?

NOTE: DO NOT take liberties with tol: very nasty things may happen

2 Likes

Since it is an array, you can convert it to a list, or append it to a list.

Edit: I just saw your file. You only need to change this one line…

Breps.append(intersect)

to

Breps += intersect

You already have a list, and you can just add the new list(or array) from intersection into the output list(Breps)

HTH

1 Like

thank you.
I wan wondering if there is a way to convert these Breps to Meshes Before Trimming them. Because it’s very optimized.
I tried the “Mesh Difference” component in grasshopper, But it keeps some extra part of mesh instead of deleting it!
Do you know how to fix it?



Ah, sorry. I’m not very familiar with meshes. :frowning_face:

1 Like

it’s ok. no problem. :slightly_smiling_face:
If I can solve it, I share the results…

What means “very optimized” ? In what sense?

Anyway I’ll prepare later on a full demo on that matter: get a BrepFace collection and do any possible thing (Trim, Split, Diff, Intersection etc etc). That said it’s not clear what are you after: i.e. what exactly you want to achive from these cones? Do a joined something from the resulting BrepFaces collection? Thicken the BrepFaces (that’s a bit tricky)? Something else?

Other than that - obviously - you can get a Mesh from any valid and manifold Brep (well … in most of cases) - but occasionally Mesh ops work when they work.

Note: you can’t auto translate C# to P (meaning that you should rewrite the demo).
Note: always do a connectivity Tree in similar cases (what is involved with what)

1 Like


Here I made a slightly faster version of @Adam_M code which is using parallel module:

from ghpythonlib import parallel 
def trim_with_all(a):
    for b in breps:
        if b == a: continue
        trimmed = a.Trim(b, 0.01)
        if trimmed != None and len(trimmed) > 0:
            a = trimmed[0]
    return a
result = parallel.run(trim_with_all, breps)

The last script using Brep.CreateBooleanUnion:

from Rhino.Geometry import Brep
result = Brep.CreateBooleanUnion(breps, 0.01)

SurfaceList Intersections.gh (42.0 KB)

3 Likes

thank you for your time and guidance.
I mean in a rhino grasshopper environment, Trimming the Meshesh takes less time while the computer calculates the process than Trimming the Nurbs objects.
I want to have a 3D pattern created from intersected Cones with or without thickness, I rather we can add thickness calculation and even the finger-joint or any other joint for the Unrolled surfaces which have adjacency for manufacturing purposes later.

this function is really helpful.
thanks for mentioning it.
is there a way we can have these operations on Meshes as well?

That’s why you should do/use a connectivity/adjacency (aka ccx relations so to speak) Tree (as shown: the left output (labeled conn) in the pics below).

BTW: A clear sketch related with your final goal could be helpfull.
BTW: Mesh/Mesh ops are not working always (but they are indeed faster). On the other hand if your core conic module is the same AND your collection follows some kind of grid … well … you should calculate the variants (middle, side perimetric etc etc) ONCE and then use them as Instance Definitions etc etc (that’s 1++M times faster).

Anyway: if we skip the thicken part for the moment (conic BrepFaces in pic1) is this 3 option output what you need?



BTW: One way to do some realistic thingy is to do your solids (pic2) , convert the “connectors” (pic3) to solids (Join + CapPlanarHoles … etc etc), assemble the connectors and then and assemble the whole combo using some sort of glue.

1 Like

thank you. it’s really helpful.
yes, it’s what I needed and it’s working properly.