[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
  • 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

Reply
  • 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

Children