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?
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
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:
Traceback:
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
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.
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.
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.
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.