[ProStructures CE (local build from latest code from RE repo as of 12/27/2021), C#] Error attaching ECData to Element.

Hi, I am trying to attach data of an ECClass to an element and keep getting this exception:

Bentley.Exceptions.EnvironmentalException : CreateInstanceOnElement failed with error code: 6

This is NOT my first ECData class or schema. I have created 3 others (about 2 years ago) that work fine. 1 is ECXAttrubutes and it attached to the DgnFile, the other 2 are ECXData and are attached to Elements.

This new Schema  imports successfully, but throws the exception when I try to attach to an element as follows:

DgnECInstanceEnabler instanceEnabler = DgnECManager.Manager.ObtainInstanceEnabler(ActiveDgnFile, baseDataClass);
if (instanceEnabler.SupportsCreateInstanceOnElement)
{
StandaloneECDInstance instance = instanceEnabler.SharedWipInstance;
IDgnECInstance dgnInstance = instanceEnabler.CreateInstanceOnElement(callout, instance, false); // <<-- exception is thrown HERE
SetProperties(dgnInstance, bData);
dgnInstance.WriteChanges();
}

callout is a TextNodeElement

instance is the correct ECClass from my schema

I modeled this new Class and the import and attachment process after one of my existing ECXData classes and for whatever reason it is not working?

I have tried stripping my Class down to barebones and still I get this exception.

I feel like I'm missing something small but, unfortunately, "failed with error code: 6" is not very helpful?

Parents
  • Hi ,

    I am not certain if the OPM SDK provides this example however see if this code snip can help you start to get the desired results.

    MSCE SDK U16.2 Example: C:\Program Files\Bentley\MicroStationCONNECTSDK\examples\DgnEC\DgnECExample\WriteInstanceOnElementTool.cs+51

    /*---------------------------------------------------------------------------------**//**
    * Write instance on the element on first data button if it lies on some element.
    * @bsimethod                                                              Bentley Systems
    /*--------------+---------------+---------------+---------------+---------------+------*/
    protected override bool OnDataButton(Bentley.DgnPlatformNET.DgnButtonEvent ev)
        {
        //Locate an element.
        Bentley.DgnPlatformNET.HitPath hitPath = DoLocate(ev, true, 1);
    
        //If an element is located write an instance on it.
        if(null != hitPath)
            {
            InstanceInfoToWrite instanceInfo = m_writeInstanceForm.GetSelectedInstanceInfoToWrite();
            FindInstancesScope scope = FindInstancesScope.CreateScope(Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel(), new FindInstancesScopeOption());
            IECSchema schema = DgnECManager.Manager.LocateSchemaInScope(scope, instanceInfo.m_schemaName, 1, 0, SchemaMatchType.Exact);
    
            Bentley.DgnPlatformNET.Elements.Element element = hitPath.GetHeadElement();
    
            ECClass calss1 = schema.GetClass(instanceInfo.m_className) as ECClass;
            DgnECInstanceEnabler instanceEnabler = DgnECManager.Manager.ObtainInstanceEnabler(Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile(), calss1);
            StandaloneECDInstance instance = instanceEnabler.SharedWipInstance;
            foreach(PropertyInfoToWrite pInfo in instanceInfo.m_properties)
            {
            SetInstancePropertyValue(ref instance, pInfo);
            }
            instanceEnabler.CreateInstanceOnElement(element, instance, false);
            }
    
        return true;
        }

    HTH,
    Bob



Reply
  • Hi ,

    I am not certain if the OPM SDK provides this example however see if this code snip can help you start to get the desired results.

    MSCE SDK U16.2 Example: C:\Program Files\Bentley\MicroStationCONNECTSDK\examples\DgnEC\DgnECExample\WriteInstanceOnElementTool.cs+51

    /*---------------------------------------------------------------------------------**//**
    * Write instance on the element on first data button if it lies on some element.
    * @bsimethod                                                              Bentley Systems
    /*--------------+---------------+---------------+---------------+---------------+------*/
    protected override bool OnDataButton(Bentley.DgnPlatformNET.DgnButtonEvent ev)
        {
        //Locate an element.
        Bentley.DgnPlatformNET.HitPath hitPath = DoLocate(ev, true, 1);
    
        //If an element is located write an instance on it.
        if(null != hitPath)
            {
            InstanceInfoToWrite instanceInfo = m_writeInstanceForm.GetSelectedInstanceInfoToWrite();
            FindInstancesScope scope = FindInstancesScope.CreateScope(Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel(), new FindInstancesScopeOption());
            IECSchema schema = DgnECManager.Manager.LocateSchemaInScope(scope, instanceInfo.m_schemaName, 1, 0, SchemaMatchType.Exact);
    
            Bentley.DgnPlatformNET.Elements.Element element = hitPath.GetHeadElement();
    
            ECClass calss1 = schema.GetClass(instanceInfo.m_className) as ECClass;
            DgnECInstanceEnabler instanceEnabler = DgnECManager.Manager.ObtainInstanceEnabler(Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile(), calss1);
            StandaloneECDInstance instance = instanceEnabler.SharedWipInstance;
            foreach(PropertyInfoToWrite pInfo in instanceInfo.m_properties)
            {
            SetInstancePropertyValue(ref instance, pInfo);
            }
            instanceEnabler.CreateInstanceOnElement(element, instance, false);
            }
    
        return true;
        }

    HTH,
    Bob



Children
  • HI Bob, thanks for replying. That example is a lot like what I am doing. And as I said in my post I have 2 other existing, completely working, ECClasses that I am Creating instances on Elements. just for some reason this one is throwing that exception??

  • Uh, Nevermind. I found the problem... I knew it was something small/stupid I was overlooking!

    I am building the Schema programmatically and in my schema, I have a couple of "struct" classes defined like this:

    ECClass structClass1 = new ECClass("Struct1", true);  // true denotes that is is in fact a "IsStruct" class

    ECClass structClass2 = new ECClass("Struct2", true);

    then my Main Class is made up of the Struct classes (and some other stuff), kinda like this:

    ECClass mainClass = new ECClass(DataClassName, true);  // ROOT CAUSE of Error: This Class must NOT have the "true" IsStruct parameter
    mainClass.DisplayLabel = "Some Label Name";
    prop = new ECProperty("PropInfo1", structClass1);
    prop.DisplayLabel = "Struct1 Data";
    mainClass.Add(prop);
    prop = new ECProperty("PropInfo2", structClass2);
    prop.DisplayLabel = "Struct2 Data";
    mainClass
    .Add(prop);

    I had that IsStruct parameter in there, but should not have had it there for the Main Class. Darn, my bad! I wish these small/stupid mistakes wouldn't take me a day to figure out!

    Answer Verified By: Robert Hook 

  • ECClass mainClass = new ECClass(DataClassName, true); 

    It would help if the documentation were more complete.  DgnPlatformNet help fails to document the ECClass constructor and its arguments.

    ECClass

    The SDK examples don't help: ..\examples\IModels\DgnIModelNETExample\src\SampleECProvider.cs uses an undocumented interface IECClass, which has only one argument (the class name).

    How about better documentation, ?

    Using good old Bentley Class Editor from V8i SDK to check whether schema is correct. Even though this tool is obsolete, designed for V8i, is still valuable for these types of analysis

    Good suggestion!  Can anyone explain why there isn't a CONNECT version of the Class Editor?

     
    Regards, Jon Summers
    LA Solutions

  • Hi All ( and ),

    I added a topic: CONNECT APIs > EC > Class Editors (anchor) in hope to provide the most current information/links available with respect to Bentley BIS and Custom Schema management (products, services and references).

    Please let me know of any other suggestions to help further improve this topic's navigation to related information/references.

    HTH,
    Bob 



  • I added a topic:

    Thanks. I am not sure whether it is good idea to mix EC schemas and BIS, because they are not compatible and "live" in another words. So it can be confusing to think e.g. about BIS in context of Bentley Class Editor and vice versa to think it is possible to chek EC schema in iModel Schema Browser.

    Please let me know of any other suggestions

    What is not clear is whether Bentley Class Editor, as delivered with OPA, requires extra license. If I remember right, V8i Class Editor required own license, but I do not see it in my license pool now ... and when I tried to install OPA and started BCE, I did not see any license consumed and no information about evaluation or missing license was displayed.

    With regards,

      Jan