mcneel / rhino.inside

Sample Projects for Rhino.Inside
MIT License
382 stars 169 forks source link

Rhino Inside AutoCAD: Creating headless document causes inconsistent state and fatal error/crash #291

Open ThomasMahon opened 1 year ago

ThomasMahon commented 1 year ago

We need to set the units of the Rhino inside document in our AutoCAD application. Using the following for debug builds works fine:

var style = WindowStyle.Normal;

_rhinoCore ??= new RhinoCore(new[] { $"/scheme={schemeName}" }), style);

var rhinoDoc = RhinoDoc.ActiveDoc;
rhinoDoc.ModelUnitSystem = this.GetRhinoUnitSystem(internalUnits);

However, for release builds we don't need the UI, so a headless version is required. However:

  1. It doesn't create a document,
  2. It's therefore not possible to set the units, and
  3. What document exactly are we using?
  4. If we create a headless document, the application becomes unstable and inadvertently crashes AutoCAD without warning. No breakpoints hit either, its fatal.
var style = WindowStyle.NoWindow;
_rhinoCore ??= new RhinoCore(new[] { $"/scheme={schemeName}" }), style);

var rhinoDoc = RhinoDoc.CreateHeadless("...a mm template file");
rhinoDoc.ModelUnitSystem = this.GetRhinoUnitSystem(internalUnits);

We've checked the validity of the RhinoDoc.ActiveDoc straight after creating the headless doc and its valid and its units are successfully set. var style = WindowStyle.Hidden has also been tested and it seems to be stable, however it always displays the splash screen which we don't want. Rhino.UI.Dialogs.KillSplash() doesn't seem to work.

What is the correct procedure?