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
  • Hallo Stanislav,

    Yes this is possible using the ElementTemplateMgr class in the Bentley.MstnPlatformNET.XDataTree name space in the ustation.dll assembly.

    See the example below:

    public static bool ApplyElementTemplate(string elementTemplatePath, BDE.Element element, bool addTemplateReference)
    {
        if (!(element is BDE.DisplayableElement)) return false;
        var template = ElementTemplateMgr.FindTemplateByPath(elementTemplatePath);
        if (null != template && null != element)
        {
            return ElementTemplateMgr.ApplyTemplateDefaultsToElement(ref element, template, addTemplateReference);
        }
        return false;
    }
    


    HTH
    Francois
Reply
  • Hallo Stanislav,

    Yes this is possible using the ElementTemplateMgr class in the Bentley.MstnPlatformNET.XDataTree name space in the ustation.dll assembly.

    See the example below:

    public static bool ApplyElementTemplate(string elementTemplatePath, BDE.Element element, bool addTemplateReference)
    {
        if (!(element is BDE.DisplayableElement)) return false;
        var template = ElementTemplateMgr.FindTemplateByPath(elementTemplatePath);
        if (null != template && null != element)
        {
            return ElementTemplateMgr.ApplyTemplateDefaultsToElement(ref element, template, addTemplateReference);
        }
        return false;
    }
    


    HTH
    Francois
Children
No Data