[CONNECT Update 16 C++] Has Element Property X?

How can we find programmatically whether a DGN element has a particular property?

For example, several elements have a Length property.  It's valid for lines, line-strings, arcs and I believe curve vectors in general.  The picture is blurred because sometimes the property name (not its display name) is Length and sometimes TotalLength. But can I determine that fact programmatically: I'm looking for fictitious method something like HasProperty (ElementHandleR eh, L"className", L"propName")?

In particular, for my current project I want to know whether a DGN element has the Bearing or Azimuth property.  A simple DGN line element has that property, but what other element types?

  • Hi Jon,

    How can we find programmatically whether a DGN element has a particular property?

    my feeling is that your question, even when right, smells a bit, because it mixes DGN element (persistence format) and how it is represented in API (which itself is wide topic, as elements are represented in different ways, depending on used API).

    For example, several elements have a Length property. 

    When an element has "length" in geometry meaning, it likely implements ICurvePathQuey API, so it can be represented as curves and length can be calculated.

    The picture is blurred because sometimes the property name (not its display name) is Length and sometimes TotalLength.

    I think it is usually when both names make sense: A segment in LineString has Lenght, but the LineString itself has TotalLength.

    Complete "inheritance chain", how these naming is defined, can be checked in DGN EC schemas.

    But can I determine that fact programmatically

    I think, when code access DGN element property (so data persisted in element), the code "should know" what properties are accessible through specific ElementHandler(s).

    When you do not want to go by "pure API" way and to use ICurvePathQuery, you can ask for intrinsic EC properties of particular element and to check, whether Length or TotalLength exist.

    I want to know whether a DGN element has the Bearing or Azimuth property.

    I am not familiar with Bearing mode, but if I remember right, Bearing / Azimuth is not element property, but angle readout direction mode, set for specific model. I have not enough time, but I do not see anything like Bearing / Azimuth defined for EC representations of DGN elements.

    Can you share more details what do you want to achieve (example DGN, some screenshots...)?

    Regards,

      Jan

  • Can you share more details?

    Using MicroStation built-in tools, you can create a text element with a text field that shows the host line's Element.Direction property.  By formatting the label, you can show either direction or azimuth (or both)...

    When an element has "length" in geometry meaning, it likely implements ICurvePathQuey API, so it can be represented as curves and length can be calculated

    Of course you're correct, but that doesn't answer my question.  The reason I want to be able to find an element property is so that it can be used in a  text field.  I can calculate a length using the API, but (a) there's no way to put that static calculated length into a text field and (b) that doesn't enable automatic update of the field when a user changes an element.

    See the LowCostLabeller freeware app.

     
    Regards, Jon Summers
    LA Solutions

  • By formatting the label, you can show either direction or azimuth (or both)...

    So it is not element property, but calculated property, when Direction (which itself is calculated, not native, property) is represented in different ways. We are

    The reason I want to be able to find an element property is so that it can be used in a  text field.

    So you do not want to search for DGN element property (as stated in your original question), but element EC property, that can be intrinsic (both native like vertex coordinates, and calculated like Total Length or Azimuth) or extrinsic (external data, attached on element).

    For this situation, to analyze available intrinsic EC property, as I mentioned earlier, should work.

    I assume, part of the definition of the field is also specification what ValueFormatter should be used to receive final formatted string.

    you can show either direction or azimuth (or both)...

    Input there is Direction, which is calculated EC property, available for Segment object.

    Whether it is represented as Azimuth or Bearing is not element property, but a result of used AngleFormatter, and part of Text Field definition.

    With regards,

      Jan

  • Whether it is represented as Azimuth or Bearing is not element property

    I'm not sure that I understand what you're telling us.  A line element has a read-only Direction property.  In EC Schema terms, that's a DirectionClass property.

    Line Props

     
    Regards, Jon Summers
    LA Solutions

  • A line element has a read-only Direction property

    Direction is not DGN element property, no such information is stored in DGN file ... I assume you know it (and you asked specifically for DGN element properties).

    Direction is EC property, and specifically, it is calculated property (unlike "native" properties like coordinates, that can be displayed as stored in DGN), derived from the line coordinates.

    In EC Schema terms, that's a DirectionClass property.

    DirectionClass is PropertyFormatter, inherited from FormatterBaseClass, not element property. The formatter, used for particular PropertyPane, takes input data and convert it to displayable format string.

    Regards,

      Jan

  • You can try to get all instances available on a specific element. And then check if the individual instance has a specific property:

    //ECQueryProcessFlags flags = intrinsic or extrinsic

    ECInstanceList GetElementProperties(ElementHandleCR element, ECQueryProcessFlags flags)
    {
    ECInstanceList ecInstanceList;
    DgnECManagerR dgnECManager = DgnECManager::GetManager();

    FindInstancesScopePtr scope = FindInstancesScope::CreateScope(element, FindInstancesScopeOption(DgnECHostType::Element));
    ECQueryPtr findAll = ECQuery::CreateQuery(flags);

    for each (DgnECInstancePtr instance in dgnECManager.FindInstances(*scope, *findAll))
    ecInstanceList.push_back(instance);

    return ecInstanceList;
    }

    Also, if you know Schema-Class, then you can prepare ECQuery accordingly.


    This is a test

    Answer Verified By: Jon Summers 

  • You can try to get all instances available on a specific element.

    Thanks for the code how to ask for EC properties, the approach I mentioned as one from possible solutions.

    Also, if you know Schema-Class, then you can prepare ECQuery accordingly.

    I think it would be BaseElementSchema or DgnElementSchema in this case.

    Regards,

      Jan