This articles discusses Python classes for handling EC Data programmatically. By EC Data we mean information about a DGN file, model or element. That information is stored in a DGN file. The data are linked to an object via its unique Element ID. An Element ID is a 64-bit integer that is unique in the context of a DGN file.
MicroStation stores EC data about a DGN file, a DGN model or DGN elements. Some data are added automatically by MicroStation. For example, the Total Editing Time is a statistic stored about each DGN file. As a user edits a file, MicroStation updates the Total Editing Time value.
Other data may be added by an application or a user: a user might want to use Item Types to annotate DGN elements in a DGN file. Item Types use a simple, user-defined, EC Schema.
An
EC Instance
is an object that stores EC instance data about a DGN file, DGN model or DGN Element.
You interrogate a DGN object to find a list of ECInstances linked to that object.
An EC Schema is the in-memory representation of a schema as defined by ECSchemaXML. Many schemas are delivered with MicroStation. You'll find them in the ECSchemas sub-directory of MicroStation's installation. On my computer, that's
C:\Program Files\Bentley\MicroStation 2025\MicroStation\ECSchemas
Each schema is an XML file, so you can read it with a plain text editor or, preferably, an XML editing app. There are some mentioned here.
Read but don't edit!
An EC Schema defines one or more EC classes. For example, schema DgnFileSchema defines class DgnFileProperties. A class defines a number of EC Properties. For example, DgnFileProperties defines property TotalEditingTime.
An EC Property describes the data that can be attached to a DGN object as EC Instance data. Data may be numeric, text, or an array.
To interrogate a DGN file programmatically to find instance data, use an
ECQuery.
An ECQuery lets you instruct your code where to look (i.e. DGN file, DGN model or DGN element)
and what to look for (i.e.
EC Schema
and
EC Class).
Help for the MicroStationAPI tells us …
An ECQuery is somewhat analogous to a SQL query and is used with DgnECManager.FindElementInstances to find ECInstances that satisfy the query's 'where' clause.
Use AddSearchClass to specify what ECClasses of ECInstances you wish to find. Use SetSelectProperties to indicate whether returned ECInstances should include their values (or just InstanceId) Use SetWhereCriterion to specify a 'where clause' Use SetPropertyValuePreFilter to filter ECInstances based on testing all of their property values, e.g. similar to a full text search.
The Dgn EC Manager.
Help for the MicroStationAPI tells us …
DgnECManager handles persistence of ECInstances including CRUD operations for ECN.Instances and EC.RelationshipInstances and "FindElementInstances" operations.
It also handles ECSchema discovery and locating.
Several examples of EC programming are installed with MicroStation Python.
This page tells you
how to find them
on your computer.
Post questions about MicroStation Python programming to the
MicroStation Programming Forum.
is a top-level object that lets us create other EC objects to create an application.
DgnECManager.GetManager() is a class method.
It lets you obtain an EC Manager object, which you use subsequently to manufacture other EC class instances.
from MSPyECObjects import *
mgr = DgnECManager.GetManager()
EC Examples
Questions