An option to enable a headless ActiveDoc #703
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Many Grasshopper plugins rely on
RhinoDoc.ActiveDoc
for things like tolerances and units. By default, a Compute instance does not instantiate anActiveDoc
, which results in aNullReferenceException
when plugins attempt to access its properties. There are workarounds that rely on theGrasshopper.Utility
class, but those have to be implemented by the plugin's developer, which means that a number of third-party plugins cannot run on Compute.Purpose
The purpose of this pull request is to give users the option to create a headless
RhinoDoc.ActiveDoc
when they launch an instance of Compute. This will allow Grasshopper plugins to accessRhinoDoc.ActiveDoc
properties without throwing an exception.Description
The users will now be able to set a local environment variable called
RHINO_COMPUTE_CREATE_HEADLESS_DOC
. The value of this variable can be set to eithertrue
orfalse
withfalse
being the default. This variable is checked by theLoad()
method of thecompute.geometry.Config
static class and its value is assigned to theCreateHeadlessDoc
property.Each time the
GrasshopperSolveHelper
method of theResthopperEndpointsModule
is invoked, it checks whetherConfig.CreateHeadlessDoc
is set totrue
. If it is, a brand new headless document is instantiated with tolerances and units determined by theinput
object. To clarify, a brand newActiveDoc
is created at a worker level for each Compute request.Testing
This branch has been tested with both Hops and direct REST API calls from Python. The target Grasshopper script contained a C# component with calls to the
ActiveDoc
properties. Testing from Python was designed to flood several Compute workers with concurrent requests, each containing a unique combination of tolerances and units. Consistency between input ActiveDoc settings and the settings reported by the Grasshopper script was checked for each invocation to rule out possible conflicts between parallelActiveDoc
instances. No discrepancies or inconsistencies have been identified while testing under significant load.