How to "open" DGN files in headless rhino doc

Hi all,

I’m writing a program to consume DGN files in a headless Rhino environment (using Rhino.Inside), and I’ve run into a few limitations.

Specifically, I want to open a DGN file in a headless document while preserving the units of the DGN file, just like opening a file via Rhino’s UI Open command.

Here’s what I’ve discovered so far:

  • RhinoDoc.CreateHeadless(null) + doc.Import(dgnFile) does not preserve the DGN units. Geometry gets scaled to mm (default template units of the headless doc).

  • RhinoDoc.OpenHeadless(path) works exactly as I want for 3dm files, but it can only accept 3dm files :slightly_frowning_face:.

  • FileDgn.Read(path, doc, options) essentially just calls doc.Import, and the FileDgnReadOptions do not expose an “Open” mode or a “ScaleGeometry” option like other file read options do.

Are there any work arounds or methods I’ve missed?

Hi Jedd,

I’m looking into this now. Can you point me to the FileReadOptions you speak of when you say, “expose an “Open” mode or a “ScaleGeometry” option like other file read options do”?

Tim

Nevermind. I see that it’s part of the base class. I just knew I had never done that in the derived classes I had done for the various file types.

If you try something like this does it do what you want?

      FileDgnReadOptions options = new FileDgnReadOptions();
      RhinoDoc mydoc = RhinoDoc.OpenHeadless("C:\\Users\\tim\\Desktop\\MACH001.dgn", options.ToDictionary());

OpenHeadless is overloaded. One takes a archivable dictionary and that will call the appropriate plugin’s ReadFile().

Thanks @tim,

This is exactly what I’m looking for.

I think I must have initially dismissed this being a potential option, because the other OpenHeadless overload throws if you call it with anything other than a 3dm extension.