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?
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.
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:
line 1263, in ExtractSurface, “C:\Users\ruy\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\surface.py”
line 27, in script
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).
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.