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.
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 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.
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.
@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)?
@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.
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.
@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.
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.
@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.
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