[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