Could someone help me understand how to move from a GeometryBase data type into its actual object type. I am kinda new to C# so bear with me. How do I go from geometrybase type to a polycurve type? I guess I am asking after getting to the geometrybase type how do I pivot to its intended class to access methods of interest. Is there something I am missing conceptually ?
here is some basic code I was noodling with. In this case I would like to convert any polycurves that have the name Test to nurbs curves. But I cant access the ToNurbsCurve method because its actually a geometry base not a polycurve despite reading out like a polycurve when calling .tostring().
Thanks !
ObjectTable doc_objs = doc.Objects;
LayerTable l_table = doc.Layers;
//RhinoApp.WriteLine(l_table.GetType().ToString());
foreach (var ott in doc_objs)
{
//RhinoApp.WriteLine(ott.ToString());
//RhinoApp.WriteLine(ott.Name);
if (ott.Name == "Test")
{
var geom = ott.Geometry;
RhinoApp.WriteLine(geom.ToString());
if (geom.ToString() == "Rhino.Geometry.PolyCurve")
{
var targ_c = geom.ToNurbsCurve();
}
//targ_geom.Add(ott);
}
}
Once you have made your geometry you need to add it to the document, you should have a reference to a document but if not you access RhinoDoc.ActiveDoc
Then you can access the ObjectTable which provides many Add methods. doc.Objects.Add(mygeometry);
You can also pass in the Object Attributes as a parameter which will allow you to define which layer the geometry is on.
I am just a little confused because when I loop through all the objects within the object table and print them I see that they are Rhino.Geometry.PolylineCurve but I cant seem to access any methods from that class ? What could I be missing ?
ObjectTable doc_objs = doc.Objects;
foreach (var ott in doc_objs)
{
var test_obj = ott.Geometry;
RhinoApp.WriteLine(test_obj.ToString());
}