Internally, MicroStation uses the smallest possible measurement: the unit-of-resolution (UOR). The C++ MicroStationAPI. NET API and Python also use UORs. MicroStation VBA does not use UORs, preferring to present measurements as a human wants to see them (metres, feet, etc).
As a Python developer, you may sometimes want to convert between UORs and real-world units (but see also the various available formatting classes). Suppose you get the length of a DGN line: its length will be found in UORs. To convert to the real world, you need to divide by the number of UORs per master unit used by the current DGN model.
Here is function GetUorsPerMaster(dgnModelRef: DgnModelRef)
,
which returns the number of UORs in the passed DgnModelRef
.
By default, the function uses the active model reference, so you don't have to pass a DgnModelRef
in many cases.
Python also provides a shortcut function if you want to convert UORs to metres. That saves some intermediate calculation if your DGN model has master units of, say, feet and you want to convert those measurements to metric.
def GetUorsPerMeter (dgnModelRef: DgnModelRef = ISessionMgr.ActiveDgnModelRef)->float: '''Get the ratio of units-of-resolution per meter for specified model reference. If you don't specify a model then the active model is assumed.''' dgnModel = dgnModelRef.GetDgnModel() modelInfo = dgnModel.GetModelInfo() # Convert MicroStation units-of-resolution to meters uors: float = modelInfo.GetUorPerMeter() return uors
def GetUorsPerMaster (dgnModelRef: DgnModelRef = ISessionMgr.ActiveDgnModelRef)->float: '''Get the ratio of units-of-resolution per master unit for specified reference, by calling a static method of ModelRef, passing the DgnModelRef as an argument. If you don't specify a model then the active model is assumed.''' # Convert MicroStation units-of-resolution to master units uors: float = ModelRef.GetUorPerMaster(dgnModelRef) return uors
I wrote those examples because I was confused by Python's provision of two similar functions whose call syntax is quite different.
With GetUorsPerMeter()
, we obtain an intermediate data class ModelInfo
from the
DGN model, and interrogate that for UORs using uors = modelInfo.GetUorPerMeter()
.
With GetUorsPerMaster()
, we call a static method (also known as a class method) of ModelRef
,
pass our DGN model as a parameter: uors = ModelRef.GetUorPerMaster(dgnModelRef)
.
I hope those examples clarify things for you too!
Python provides several formatters, which take a number (length, area, volume, DPoint3d) and convert to a nice-looking string.
Post questions about MicroStation programming to the MicroStation Programming Forum.