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...
Hi Stanislav,
please follow the best practices!
Plus please use recommended subject format [<product> <version> <API>] <subject>. It makes posts navigation much easier.
[<product> <version> <API>] <subject>
Also, use Insert > Insert code tool every time you want to share a code snippet (even one line only). To have code inserted as normal plain text does not look good (and readable).
Stanislav Konrád said:In 2016 Jan Šlegr wrote:
Where, in what discussion I wrote it? Why you do not link the discussion?
And what is more important, for what API version I wrote it? What was true 4 years ago could changed in a meantime.
Stanislav Konrád said:Is there a way to set attributes to Element according Element Template
Did you search for existing discussions? Element templates have been discussed quite often.
Even when they are typically about C++, but at least the discussion can provide some insight (e.g. that it is not well documented and difficult to use API even in C++).
In NET, there seems to be ElementTemplateManager class available, but only some methods are listed in documentation, whereas more public methods exist in assembly. But they seem to be not equal to C++ MstnElementTemplateMgr. So it's about to try whether e.g. ApplyTemplateDefaultsToElement can help (unfortunately C++ ApplyElementTemplateParams does not exist in NET).
Stanislav Konrád said:I expect
I think element template is to be applied after an element is created.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Thank you very much for your answer!
Jan Šlegr said:What product do you use? What version (exactly) do you use?
Closer specification: AddIn application for OpenRoads 10.08.01.33 (OpenRoads Designer CONNECT Release 2, update 8) with MicroStation 10.13. core, C# ,NET, VS2017Prof.
Jan Šlegr said:Where, in what discussion I wrote it? Why you do not link the discussion?
Here is that discussion...last article
Stanislav Konrád said: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.
Stanislav Konrád said: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.
Stanislav Konrád said:...or similar...
I see a couple of misunderstandings in your expectation:
Stanislav Konrád said: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:
Stanislav Konrád said: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.
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,
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; } HTHFrancois
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; }