[OBD Connect Edition Update 6 C#] DgnECManagedCrudExample

Hi,

I am currently trying to adapt the 'DgnECManagedCrudExample' (https://communities.bentley.com/products/programming/microstation_programming/b/weblog/posts/ec-crud-operations-with-native-and-managed-dgnec-apis#CreateECInstancesAndRelationships) to our needs.
It works fine with the simple (custom) schema from the example.

If I try with the class 'Concrete__x0020__Column' from the 'BuildingDataGroup' schema I run into an 'EnvironmentalException' ("CreateInstanceOnElement failed with error code: 32768") when I try to create the 'IDgnECInstance'. The 'SupportsCreateInstanceOnElement' flag is also false (it´s true in case of the simple schema). I tried the other methods of creating an instance in 'DgnECInstanceEnabler' as well.

bool supportsCreateInstanceOnElement = widgetEnabler.SupportsCreateInstanceOnElement;
IDgnECInstance widgetInstance = widgetEnabler.CreateInstanceOnElement(lineElement, widgetWipInstance, false);

I have columns with that exact EC instance attached in the same model.

Am I missing something here? Is this not allowed?

Cheers

My example code:

DgnFile activeDgnFile = Session.Instance.GetActiveDgnFile();

ModelId modelId = activeDgnFile.DefaultModelId;
StatusInt statusInt;
DgnModel activeDgnModel = activeDgnFile.LoadRootModelById(out statusInt, modelId, true, true, true);

DgnECManager dgnECManager = DgnECManager.Manager;

DPoint2d startPoint = new DPoint2d(0, 0);
DPoint2d endPoint = new DPoint2d(10 * UoR, 10 * UoR);
DSegment3d segment3D = new DSegment3d(startPoint, endPoint);
LineElement lineElement = new LineElement(activeDgnModel, null, segment3D);
if (null != lineElement)
lineElement.AddToModel();

string schemaName = "BuildingDataGroup";
FindInstancesScope scope = FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnFile(), new FindInstancesScopeOption(DgnECHostType.All, false));
IECSchema schema = DgnECManager.Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);

string className = "Concrete__x0020__Column";
IECClass ecClass = schema.GetClass(className);

DgnECInstanceEnabler widgetEnabler = dgnECManager.ObtainInstanceEnabler(activeDgnFile, ecClass);
ECDInstance widgetWipInstance = widgetEnabler.SharedWipInstance;

bool supportsCreateInstanceOnElement = widgetEnabler.SupportsCreateInstanceOnElement;
IDgnECInstance widgetInstance = widgetEnabler.CreateInstanceOnElement(lineElement, widgetWipInstance, false);

Parents Reply Children
  • Hi Tilman,

    a few more comment to what wrote, as my experience from trainings I did in the past is that some topics around EC and related API are not always clear (especially what functionality is available in what situation).

    I do not know OBD API (just on very basic level), but I am pretty sure concepts are shared by all Power products (because they use the same PowerPlatform core).

    we thought creating the right EC instance (which is kinda straight forward) and attaching it to a 'CellHeaderElement' would be a reasonable solution.

    Hmmm ... probably not. It is like to when you create paper model of car and stick original logo, it does not create a real car from it.

    EC API provides unified view on different data structures, persisted in model (and I guess to dynamic in-memory only data also). So depending on ECQuery you can receive "real EC data" (so called extrinsic), as well as other data, rendered as EC data on demand, but stored in other, standard (e.g. element geometry) or custom (user data linkages, tags...), data structures (so called intrinsic).

    Even when data is attached as EC data to an element, it is not always simple to "just attach" them, because other requirements (like relationships to other EC instances) may exist. I think in limited number of situations, EC data can be attached directly, without using specialized API (that ensures everything is initialized and set correctly).

    With regards,

      Jan