Splitting a surface with a curve in grasshopper python?

I’m attempting to make a Sierpinksi Carpet for an assignment in python grasshopper. My plan is to input a square curve, turn it into a surface, divide and split that with curves to get my individual squares. Maybe that’s a flawed approach but whatever, what I can’t figure out for the life of me is how to split surface with curves. I’ve been trying rhinoscriptsyntax.splitbrep and rhino.geometry.brep.split and clearly don’t understand the correct syntax. I’m trying to split rectSrf with rectInt.

It would really make my day if someone could demonstrate how to do this, even with just an arbitrary surface and curve but I’m uploading mine as well.

sierpinski carpet.gh (6.2 KB)

Even when I just input a surface and line from Rhino, I still got errors, just different ones. To disconnect between surfaces and breps in python, and the right syntax, is really bogging me down.

I need to duplicate this functionally in python:

image

Goal:
image

Do you know how to do it without Python? Maybe you can “translate” this to Python?


divSrf_2020Dec12a.gh (11.6 KB)

1 Like

I could, I figured… maybe not the recursive part but I’m in a frustrating class that wants us to do EVERYTHING in a python component. Which leaves me here, stressing for hours on how to something in python it would take minutes in grasshopper. I get it, the power of python for advanced solutions, but I don’t like learning this way.

You need loop

sierpinski carpet.gh (11.4 KB)

If you want to cheat, just use ghpythonlib.components. (unless you are barred from that.)
It gives you most of the grasshopper components inside python.

1 Like

@christopher.ho That would work, but I’m getting a (Data conversion failed from Guid to Surface) or ((Data conversion failed from Goo to Surface) which is what I was getting on the others, leads me to believe I have a basic misunderstanding inputs… like I can’t just do ghc.SurfaceSplit(x, y)?

You need to set the correct type hint and access levels:

1 Like

@christopher.ho RIGHT! I was supposed to know that already, ok so that fixed the Goo issue, as far as me just adding a surface and curve directly from Rhino. The GUID error is in reference to internal variables though. Below I pulled in one square closed curve as ‘rect’ got the edges, divided them to get the intersection curves, turned rect into a surface and… that guid error now when I attempt to split it. Everything worked fine up until that point. I have the original type hint set to Curve.

Rhinoscriptsyntax generates objects and returns the Guid of the object, like a pointer.
Use the split from rhinoscriptsyntax:

1 Like

What is your problem ?
Do you want split surface with curves using python or you want Sierpinksi Carpet?

Ahh, that makes sense. I was trying that before though with other erros, maybe I should find a ghpythonlib solution for converting a closed curve to a surface.

He is required to use python to generate Siepinkski carpet and is looking for python help.

@anon39580149 Both. I just got stuck on the surface splitting and wanted to add some context. If I was doing this in grasshopper, and I wanted to create a Sierpinksi Carpet from any size square curve. I’d probably just make it into a surface and split it into 9 square surfaces using curves, then use a cull to remove the center square, and apply the same method to every other square. I’ve just got my hands tied behind my back in that I have to try to do that in python alone… and I suck a python.

How you will create Sierpinksi Carpet with split surface with regular components? did you try?

To infinity? No. Down to a few iterations, yes I just did. I don’t know how to loop in Grasshopper but I can copy and drag my cluster of components to repeat the original process down to every resulting square as many times as I want. For the looping, I’m going to use a recursive function in Python with a set limit.

My logic isn’t the problem, it’s finding the right python equivalents to gh components and using the correct syntax. I can’t get to any advanced parts of the script if I can’t get past the first simple steps. I choose to work with split surfaces, rather than constructing closed curves from points, that would obviously work too but I didn’t foresee something as simple as splitting a surface with 4 curves being hard in Python.

I already post two solutions with loop, and you don’t need split surface with curves.

Sierpinksi Carpet.gh (5.0 KB)

@anon39580149 I can’t say I understand exactly what you did there but I’ll figure it out. It’s clearly a better route, thanks for that!

As to my original question about splitting surfaces, it seems like I was cherry picking from different modules and expected rhinoscriptsyntax surfaces to play with rhino.geometry curves… and they don’t?

Rhinoscriptsyntax is based on pointers to geometry.
Rhino.geometry is based on actual geometry classes.
ghpythonlib is based on the grasshopper geometry class.

1 Like

Check the previous solutions with components only

using mesh is better and faster
1-create mesh plane from rectangle (square)
2-remove the center square
3-extract mesh faces boundaries and use them as new squares
4-the process repeated

To split surface with curves:

Sierpinksi Carpet.gh (19.5 KB)

1 Like

HI
You need to use recursion.like this


sierpinski carpet.gh (5.8 KB)

1 Like