Quantcast
Channel: Rhino Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 8532

GeometryBase to OnObject and Back

$
0
0

@gordon wrote:

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)

Thanks

Gordon J.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 8532

Trending Articles