Rhino.RhinoDoc vs. FileIO.File3dm


I would like to quickly switch between drawing all my objects on the screen and writing to a 3dm file, I thought I just swap my variable for Rhino.RhinoDoc with Rhino.FileIO.File3dm but this does not work since the later does not inherit from the former. Would it work with dynamic typing ? Is there somewhere an example for such a workflow?

(Menno Deij - van Rijswijk) #2

This is, in my opinion, indeed a bit strange, if not a complete PITA.
File3dm and RhinoDoc are completely unrelated.

I’m not sure how dynamic typing would help here, unless you would like to bind the dynamic method to one or the other object. IMHO that is just asking for trouble, because not type safe.

I guess you could go like this, especially if you only need to write a few geometry types.

public class SuperFileWriter
    private readonly RhinoDoc _doc;
    private readonly File3dm _file;
    public SuperFileWriter(RhinoDoc doc)
        if (null == doc) throw new ArgumentNullException("doc");

        _doc = doc;

    public SuperFileWriter(File3dm file)
        if (null == file) throw new ArgumentNullException("file");

        _file = file;

    public Guid AddBrep(Brep b, ObjectAttributes att = null)
        if (null != _doc)
            return _doc.Objects.AddBrep(b, att);
        return _file.Objects.AddBrep(b, att);

    public Guid AddSurface(Surface surface, ObjectAttributes att = null)
        if (null != _doc)
            return _doc.Objects.AddSurface(surface, att);
        return _file.Objects.AddSurface(surface, att);

    // etc. etc.


Yes such a wrapper Class is what I am looking for. Has anyone done this already? Including later manipulations on the Layer Table.

(Menno Deij - van Rijswijk) #4

Not to my knowledge. If anyone’s going to do it, it would be a good contribution to RhinoCommon on Github.