Srfsplit for ghpython

Hi there,

I’m doing my first scripts in ghpython, and want to trim a surface with a curve. In grasshopper I would use the srfsplit item, but haven’t found any equivalent script command. The split brep command looks like it could do the job, but it doesn’t take curves as cutters, only breps. Is there anything I’m missing?


Gh uses this:

Dunno how that goes in python.

That is what I’m looking for, but as you noted I haven’t found it in python. As far as I can tell not all rhinocommon sdk methods have been implimented in python

thanks a lot

Hi @ruy.sevalho

well, All of RhinoCommon is available in Rhino’s Python. We use IronPython, and it can access any C# method. That’s why we chose it.

I made a quick example for you, that uses a subset of the Python sample from:

The SplitBrepFaceWithCurve can now be used like any RhinoScriptSyntax function, so it’s easy and compatible with other rs.* code you might find. (5.6 KB)

I hope this helps,


Giulio Piacentino
for Robert McNeel & Associates

1 Like

Thanks a lot Giulio.

I’m not a professional coder by any means, so let me just get this straight. Using IronPython I can import any C# method, including all of RhinoCommon? I can use the methods side by side with rs.* syntax?

I think that’s what you said, just seeing if I misundertstood something.

Once again thanks a lot

The answer to this question is: Yes.

Yes. rhinoscriptsyntax can be the easiest way to start; then you can use RhinoCommon when you need special parts that are not in rhinoscript. Basically, it all revolves around adding and finding parts in the rhinoscript document.


I had to put the script aside until now. I’ve used your implementation to do the surface split. The next spet was trying to pick the one I wanted. I tried to use the rs.ExtractSurface, but get an error message:

Runtime error (ArgumentTypeException): expected Guid, got NoneType

line 1263, in ExtractSurface, “C:\Users\ruy\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\”
line 27, in script

Any ideia what’s going on?

Thanks (13.9 KB)

Looks like you’re mixing rhinoscript and RhinoCommon methods together in the same script - see these and other discussions:

Solved by changing the return value of your function to return the object’s Guid via scriptcontext.doc.Objects.Add____() rather than the object itself.

def SplitBrepFaceWithCurve(brep, crv):
  brep_id = doc.Objects.AddBrep(split_brep)
  return brep_id
1 Like

Yes, as @qythium is mentioning, if you want to use RhinoScript methods, you’ll work with Guids.
It’s in part my mistake: I should have added the last line that @qythium mentions to the sample above.

Thanks everyone.

Just to see if I’m getting the fundamentals straight. In rhinoscript when you do something like a = rs.addpoint() in the a variable is only stored the GUID to the object. In the RhinoCommom method if I do something like a = Rhino.Geometry.Point3d(0, 0, 0) it actually returns the whole Rhino object (geometry plus data wraped around it).

Once again thanks a lot

Hi Ruy,

I am reposting this graphics from here.

Let’s first of all have a look at the various available ways to reference geometry and data in ghPython:
ghdoc is the standard document for rhinoscriptsyntax. We can use it all the time and it is meant to be as quick as possible, in order to slow down rhinosciptsyntax in Grasshopper as little as possible.

It is also possible to just reference or create geometry in memory using RhinoCommon methods.

The third and last document is the usual Rhino document, which is also accessible in ghPython: Rhino.RhinoDoc.ActiveDoc .

All these three styles are valid and useful for certain purposes and code writing styles.

Specifically, you are asking to take data from ghdoc, obtain the geometry, and finally add it to the Rhino document. This is essentially baking in ghPython, right?

I am attaching an example.

When you have a document available and a Guid, you can use rhinoscriptsyntax.coerceXXX(guid) in order to obtain geometry, or specific types of geometry.

Similarly, scriptcontext.doc.Objects.AddXXX() allows to add geometry to the document. There are lots of variants for this. You can refer to the RhinoCommon documentation for all methods in the ObjectTable class, or all methods in the ghPython one are on GitHub. (7.5 KB)


Thanks Giulio,

At some point onde does need to have some understanding of what’s going on “under the hood”, i’lll look into it. I have to say your responses are very quick and thoughtful, keep up the good work.


1 Like