CONNECT C# Addin Element Template

Is there a way to set attributes to Element according Element Template from attached dgnlib  (C#) ?
In 2016 Jan Šlegr wrote: "I guess there is no documented NET API available", may be after time...

I expect something like this:

ElementTemplateCollection elementTemplates = model.GetDgnFile().GetElementTemplates();
ElementTemplate elementTemplate = elementTemplates.FindByName(<template group name>\<template name>);
LineElement element = new LineElement(.....
elementTemplate.Apply(element);

...or similar...

Parents Reply Children
  • Hi Stanislav,

    Closer specification

    Well, they are not "closer specification", but mandatory (and often crucial) specifications. Whether used product is MicroStation or OpenRoads Designer changes the whole discussion often.

    Here is that discussion...last article

    I think even when situation is better now, because templates were discussed several times, so at least a minimal knowledge base is available. But it's not perfect, because even in C++ API, MstnElementTemplateMgr structure methods are not described enough.

    ...or similar...

    I see a couple of misunderstandings in your expectation:

    • Do not confuse template element with element template:
      • Template element, used in an element constructors, has to be already existing element, that is used to copy properties from. This concept has existed for very long time, before Templates were introduced.
      • Element template is a set of setting, applied to element and (alternatively) linked with the element, so even it's similar, it's not the same.
    • I think the template can be applied to existing element only (but I did not test it).
    Is there a way to set attributes to Element according Element Template from attached dgnlib  (C#) ?

    I think there is, but it requires some research and extra study, because I was not able to find any discussion about ElementTemplateMgr.

    I recommend:

    • Read all discussions about element templates in C++, especially where MstnElementTemplateMgr is discussed.
    • Check C++ documentation (but it does not provide too much valuable information in this case).
    • In Visual Studio (or using a decompiler like DnSpy) check what methods are offered by ElementTemplateMgr (available in ustation.dll assembly).
    • Also check this discussion. I like an idea to assign element template through EC representation.
    I expect something like this:

    Well, I think the workflow should be similar, but used classes and methods different. And it's not quite clear from available documentation, how much of some tasks are done automatically and what have to be implemented.

    • Check whether template exists in active DGN file
    • When not, iterate DGNLIBs to find the template and copy the template to active model
    • Get template id
    • Create an element
    • Assign template id to the element

    I am not sure whether the element has to be added to a model before the template is assigned. Also, it makes sense to encapsulate the operations by single transaction to ensure it's represented as one step in MicroStation interface.

    With regards,

      Jan