Getting the Units of the Active Document
Windows only
Overview
There are two unit systems associated with a document, model and page units. The ON_UnitSystem
class makes it easy to work with custom units. The Rhino document class contains two functions to return these unit systems:
const ON_UnitSystem& CRhinoDoc::ModelUnits() const;
const ON_UnitSystem& CRhinoDoc::PageUnits() const;
More information
The unit system of the active document is stored on an ON_3dmUnitsAndTolerances
class that is located on the CRhinoDoc
object.
If you inside of a CRhinoCommand
-derived object’s RunCommand()
member, you can get the current units system as follows:
const CRhinoDocProperties& doc_props = context.m_doc.Properties();
const ON_3dmUnitsAndTolerances& units_tolerances = doc_props.ModelUnitsAndTolerances();
ON::LengthUnitSystem units_system = units_tolerances.m_unit_system;
As a shortcut, you can do the following:
ON::LengthUnitSystem units_system = context.m_doc.UnitSystem();
If you outside of a CRhinoCommand
-derived object’s RunCommand()
member, you can get the current units system as follows:
CRhinoDoc* doc = RhinoApp().ActiveDoc();
if (nullptr != doc)
{
ON::LengthUnitSystem units_system = doc->UnitSystem();
}