Hi,
So in our goal to get our code ready for Rhino 6, we are doing a bunch of RhinoCommon conversion, and along the way a lot of Interop’s are happening between converted RhinoCommon code and older .NET sdk code.
As part of this I have the need to convert from a GeometryBase Object to a OnObject (And back again)
I have some code that starts out like this:
File3dm model=File3dm.Read(fileName);
List<OnObjects> objects = new List<OnObject>();
foreach(File3dmObject fObject in model.Objects)
{
GeometryBase gb =fObject.Geometry;
OnObject obj = *****Need converter here**** from gb;
if(obj==null) continue;
Objects.Add(obj);
}
I started writing a function to do this per object type, like this:
private static OnObject toObj(GeometryBase gb)
{
Brep b = gb as Brep;
if (b!=null)
return (OnObject)Interop.ToOnBrep(b);
Curve nc=gb as Curve;
if (nc != null)
return (OnCurve) Interop.ToOnCurve(nc);
return null;
}
But was hoping maybe there is a built in way to do this with some intptr or something?
(I also have code elsewhere that needs to take an OnObject to return a GeometryBase)
I can write some cleaner implementations of this in the future, but the above should work for now. Once I have something else in place, we can just tweak the contents of those two functions. This is on my todo list at http://mcneel.myjetbrains.com/youtrack/issue/RH-35239
If you have a Rhino.Geometry.Curve from RhinoCommon and you need a ``OnCurveobject for Rhino .NET, the use Steve'sToOnObject``` static function listed above.