I have a closed curve and I would like to automatically dissolve all crvs if they are shorter than “X”.
This is my attempt but I got stuck. Can someone help me? Is my attempt even a good approach?
My idea is:
to get the vertices of the all crvs
replace the vertices of the short crv(s) with a single midpoint
connect all vertices / points to a closed crv again
But I dont know how to remove the endpoints of the short crv from an overall list of all vertices of the closed crv.
I’ll send the file if you want to take a look for yourself.
Assuming polylines, their underlying RhinoCommon class actually has two methods that does exactly this, which are not exposed in Grasshopper (see documentation here and here):
Seems like you have an old version of Rhino / Grasshopper / or Python because I am getting an error:
Note that I am using rhino 8 but I tried it with my rhino 7 version and still got the same error.
Do you know a solution? I am not very familiar with python
I’m on the latest Rhino 7 Service Release (7.37.24004.15001, 2024-01-04). What is the error you’re getting?
Based on your bottom screenshot, it looks like you need to set the Polyline input parameter type hint to Polyline. Here’s how with the Rhino 7 GHPython component:
I believe it’s roughly the same with the new Rhino 8 script editor, but you might also have to run it in IronPython mode. That said, you can also just keep using GHPython, if you come across issues with the new editor (there is quite a bit of early day jank/issues).
Edit: Just had a look in Rhino 8 and it appears this is another case where CPython-RhinoCommon interop appears borked (i.e. a Polyline type is passed as list):
import Rhino.Geometry as rg
polyline = rg.Polyline(polyline)
polyline.CollapseShortSegments(tolerance)
a = polyline.ToPolylineCurve()
the script node casts a polyline to a list of Point3d, which is why you’ll need to create a Polyline first in order to run the code. Might be a bug.
EDIT: On a side note: Personally I’m not a fan of using upper case variables as that can lead to bugs, especially when calling them the same as classes from libraries used. In this case e.g. a from Rhino.Geometry import Polyline will cause problems.