I need to check what type of geometry a curve belongs to (line, polyline, polylineCurve…)
How can I get that Information? I am thinking about something like
if rs.CoerceGeometry(obj) = ??.ObjectType.PolyCurve:
elif rs.CoerceGeometry(obj) = ??.ObjectType.PolyLine
do something else
I cannot find the right methods for that. Any help would be really appreciated.
Thanks in advance!
How about these:
The the Python help file for details.
In addition to what Dale suggested this is another approach:
import rhinoscriptsyntax as rs
objs = rs.AllObjects()
for obj in objs:
rhcrv = rs.coercegeometry(obj)
if isinstance(rhcrv,Rhino.Geometry.ArcCurve): print 'ArcCurve'
if isinstance(rhcrv,Rhino.Geometry.PolylineCurve): print 'PolylineCurve'
if isinstance(rhcrv,Rhino.Geometry.PolyCurve): print 'PolyCurve'
rs.IsCurve, IsArc delivers sometimes not unique results. So I get True for rs.IsLine and rs.IsPolyline for one curve .But I need the exact geometry type to call different methods for each (e.g. changing start and endpoint).
isinstance(rh_geo, Rhino.Geometry.xxx) was exactly what I was looking for! I
Thank you very much!
This probably isn’t the right category, but I have been trying to learn to use the rhino3dmio.desktop nuget package for reading 3dm files, and I have found through testing that when I have a curve object and try to find out the sub type using the isArc(), isCircle(), etc, that if I feed it a circle, it tests true for isArc, isCircle, AND isEllipse!? Also, a line will test true for both isLinear() and isPolyline()!? Perhaps I am using the statements wrong? Here are some of the relevant snippets in my code (C#):
model = Rhino.FileIO.File3dm.Read(fname, File3dm.TableTypeFilter.ObjectTable, File3dm.ObjectTypeFilter.Curve);
Rhino.FileIO.File3dmObjectTable f3dobjs = model.Objects;
foreach (Rhino.FileIO.File3dmObject obj in f3dobjs)
Rhino.Geometry.Curve curveobj = (Rhino.Geometry.Curve)obj.Geometry;
// a linear line will match islinear AND ispolyline
// arcs and circles both seem to match all of isarc, iscircle AND isellipse! WTF!
curve_case = 1; // Line
Debug.Print("curve_case is linear, curve_case var = " + curve_case.ToString());
curve_case = 2; // Circle
Debug.Print("curve_case is circle, curve_case var = " + curve_case.ToString());
curve_case = 3; // Arc
Debug.Print("curve_case is arc, curve_case var = " + curve_case.ToString());
curve_case = 4; // Polyline
Debug.Print("curve_case is polyline, curve_case var = " + curve_case.ToString());
curve_case = 5; // Ellipse
Debug.Print("curve_case is ellipse, curve_case var = " + curve_case.ToString());
I’m currently using v6.22.20028.13281 of the nuget package.
You might see if tis sample helps in any way.
Thanks for the sample code. I’m in process of copying all the private bool functions (isArc, etc.) into my class code. Most of it fits within the Rhino3dmIO library, but it looks like there is one “class” (not sure what the proper nomenclature is?) that is not exposed in Rhino3dm IO! In the sample, it is “CurveIntersections” referenced on line 391, inside the “bool isPolyline()” function. Rhino.Geometry.Intersect is available, but doesn’t appear to have the CurveIntersections method?
Any idea if that is exposed in the v7 WIP nuget package? If so, maybe I’ll switch to that.
Rhino3dm is based on openNURBS. And the free version of openNURBS does not contain everything that is provided by Rhino.
I do realize that. That is what I have to work with. I see from my object browser that the Geometry Intersect class is included (mostly). For now I have just commented out the 2 lines dealing with testing if the curve is self intersecting. Once I get the rest incorporated into my main subroutine, I’ll let you know if I’m still getting multiple hits on one curve entity