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