ar0551 / Wasp

Combinatorial Design with Grasshopper plug-in (LGPL) initiated by Andrea Rossi
https://linktr.ee/gh_wasp
GNU Lesser General Public License v3.0
54 stars 14 forks source link

Use scriptcontext for tol instead of active doc #4

Closed pearswj closed 3 years ago

pearswj commented 3 years ago

Hey @ar0551, I ran into this one recently while experimenting with installing Wasp on a machine running Rhino Compute.

ActiveDoc will be null when Rhino is running in "headless" mode (as it does when running in Rhino Compute). To workaround this you can use scriptcontext.doc which defines default values for tolerances and units when no active document exists.

ar0551 commented 3 years ago

Hi @pearswj, thanks for reporting this. Quick question: how are the tolerance values defined in scriptcontext.doc, when running inside Rhino? Does it inherit the values from ActiveDoc, or has its own standard tolerance values? I am asking because I would like to retain the possibility of affecting tolerances in Wasp by changing the doc tolerance values. So I am wondering if it would make more sense to still use ActiveDoc, and switch to scriptcontext.doc only when ActiveDoc is null.

pearswj commented 3 years ago

Good question! I didn't explain that well at all. Here's what happens when you call scriptcontext.doc.ModelAbsoluteTolerance...

const double _defaultModelAbsoluteTolerance = RhinoMath.DefaultDistanceToleranceMillimeters; // 0.01

...

if (RhinoApp.IsRunningHeadless && RhinoDoc.ActiveDoc == null)
  return _defaultModelAbsoluteTolerance;
return RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
ar0551 commented 3 years ago

Allright, thanks for explaining that. And thanks again for the suggestion. I will include this in the next Wasp release.