Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4331

[V8i SS4 C#] Get EC attributes from element

$
0
0

I've done this for Items Types in CE but now I need to go back and do the same thing for V8i and EC for a customer case.

I've looked around and came up with the code below. The problem is that I get a Illegal cast error when calling ReadInstances().

There might be more problems further down so you are welcome to comment on that as well 

(sorry, I just can´t get the code formatting to work!)

public override ElementAttributeList GetAttributesFromElement(BCOM.Element element)

{

ElementAttributeList attributes = null;

if (element == null)

{

  return attributes;

}

try

{

Bentley.ECObjects.Instance.ECInstanceList instances;

instances = XmlInstanceRead.ReadInstances(

  element.MdlElementRef(),

  element.ModelReference.MdlModelRefP());

attributes = new ElementAttributeList();

foreach (Bentley.ECObjects.Instance.ECInstance instance in instances)

{

string className = instance.ClassDefinition.DisplayLabel;

foreach (IECProperty prop in instance)

{

  ElementAttribute attribute = null;

  Bentley.ECObjects.Instance.IECPropertyValue propValue = instance.GetPropertyValue(prop.Name);

  if (propValue == null)

  {

    continue;

  }

  string type = prop.Type.Name.ToLower();

  switch (type)

  {

    case "string":

    if (!propValue.IsNull)

    {

      attribute = new ElementAttribute(prop.DisplayLabel, propValue.StringValue, AttributeType.String);

    }

    break;


Viewing all articles
Browse latest Browse all 4331


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>