[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);

  • Maybe as some background information: What we are trying to achieve is to place i.e. concrete columns in the model programmatically. Since we don´t want to use the COM interface, we thought creating the right EC instance (which is kinda straight forward) and attaching it to a 'CellHeaderElement' would be a reasonable solution.

  • If I try with the class 'Concrete__x0020__Column' from the 'BuildingDataGroup' schema I run into an 'EnvironmentalException'

    Is the building product that provides that schema installed on the computer where you run your code?

    Most of us don't have the 'BuildingDataGroup' schema.  We can't emulate your environment on plain old MicroStation.

    I suggest that you create your own simple schema and develop code with that schema.  That eliminates any trouble with the 'BuildingDataGroup' schema being unavailable, or maybe requiring some additional 'environmental support', whatever that might mean.

    A 'simple schema' might be an Item Type definition.  That's easy to define using MicroStation tools.  I've written working code similar to yours for several products, using Item Types.  I've never encountered the EnvironmentalException.

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

    I agree: it is a reasonable choice and matches my experience with Item Types, which is why I'm suspicious of the 'BuildingDataGroup' schema.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Tilman,

    Building products might have handlers/listeners for their own classes. Or, Concrete__x0020__Column could be an intrinsic class. Meaning, Concrete class properties may not be persisted as "ECXAttributes". Ideally, you should use Building APIs to create the concrete columns. Let me check if someone could direct you to Building development communities.

    Thanks,

    Mangesh


    This is a test

  • 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

  • Is the building product that provides that schema installed on the computer where you run your code?

    Yes, this schema comes shipped with the workspace configuration in 'C:\ProgramData\Bentley\OpenBuildings CONNECT Edition\Configuration\Workspaces'