Force a component to recompute when model unit system is changed

Hi,
I am wondering if there is a way for a python component to recompute automatically when the model unit system is changed inside Rhino.
Let’s say the python component is actually returning the model unit system as follow :

import scriptcontext as sc
units = sc.doc.ModelUnitSystem

And then the units are changed in Rhino and we want the python component to give the new model unit system without recompute it manually. Is it possible to achieve that ?

Hello,

Not familiar with Python but there is the DocumentPropertiesChanged event handler that listens for the units (among other things). C# code below :

private void RunScript(ref object Units)
  {
    Rhino.RhinoDoc.DocumentPropertiesChanged -= CallBack;
    Rhino.RhinoDoc.DocumentPropertiesChanged += CallBack;
    Units = Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem;
  }

  // <Custom additional code> 

  private void CallBack(object sender, DocumentEventArgs e)
  {
    this.Component.ExpireSolution(true);
  }

UnitsListener.gh (3.6 KB)

3 Likes

This may work for you.