ORD | 2021 release 2 update 10 | 10.10.21.04In Ord, each element has a feature definition. Is there a way to get the feature definition for each element?I have a list of IDgnECInstance. I need to get their feature definition and descriptionmore code:
public IEnumerable<Instance> Scan(string schemaName) { var instances = GetInstances(GetSearchClasses(schemaName)); foreach (var instance in instances) { yield return new Instance() { ElementId = instance.Element.ElementId.ToString(), ClassDefinitionDisplayLabel = instance.ClassDefinition.DisplayLabel, FeatureDefinition = instance.Element.FeatureDefinition // this field doesn`t exist }; } } private IQueryable<IDgnECInstance> GetInstances(IECClass[] classes) { var query = new ECQuery(classes) { SelectClause = { SelectAllProperties = true } }; var manager = DgnECManager.Manager; var scopeOptions = new FindInstancesScopeOption(DgnECHostType.Element, true); var dgnFile = _dgnFileProvider.GetActiveDgnFile(); if (dgnFile == null) return null; var scope = FindInstancesScope.CreateScope(dgnFile, scopeOptions); var instances = manager.FindInstances(scope, query); return instances.AsQueryable(); } private IECClass[] GetSearchClasses(string schemaName) { var scopeOptions = new FindInstancesScopeOption(DgnECHostType.All, true); var scope = FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnFile(), scopeOptions); return DgnECManager.Manager.LocateSchemaInScope(scope, schemaName, 1,0,SchemaMatchType.Latest).GetClasses(); }
Hi Ivan,
because your question is about OpenRoads Designer programming, please move your question to Civil Programming forum. To move existing discussion to another forum, use More > Move tool, available under your original post. Please, do not ask again to do not duplicate discussions, but prefer to move existing one.
Ivan Petrov said:Is there a way to get the feature definition for each element?
OpenRoads Designer offers comprehensive API to work with civil objects (alignments, cants, speed tables...), both in C++ and NET. See examples delivered with ORD SDK how to access the data.
Ivan Petrov said: to get the feature definition
What is "feature definition" for you? Is it the feature name and description, or you are interested in complete definition tree (feature definition / symbology per the feature representation / annotation group / annotation definition / ...)? While to obtain name and description is simple, to reconstruct complete definition can be very complex task.
Ivan Petrov said:I have a list of IDgnECInstance.
It's not so simple. Civil model is extremely complex, modeled using tens of classes, connected using another tens of relationships, defined in many EC schemas (where some are created dynamically in memory, and other as ad-hoc structures). So to use API is preferred, although (at least) in ORD 2021 R2 not all data are available, and some can be obtained using EC Queries (or alternatively by hacking internal API).
The civil data model is not published, so when you prefer (or must) to use EC Query instead public API, you must analyze it, decompose and design proper queries by yourself.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Thanks for your reply. It is really important for me.
Jan Ĺ legr said:While to obtain name and description is simple,
I need a name and description only. Do we have some generic approach?I know only this one: to try to find a feature definition for the element, we have to go by all geometric models. it looks very expensive.
\\example for LinearEntities3d var linearEntity3ds = ConsensusConnectionEdit.GetActive() .GetAllGeometricModels() .SelectMany(_ => _.LinearEntities3d) \\ here need to iterate all the available geometric models .ToList(); foreach (var linear in linearEntity3ds) { var featureObjectSetting = linear.FeatureDefinition.DomainObject as Bentley.CifNET.ContentManagementModel.ObjectSettings; var elementId = linear.Element.ElementId var featureName = linear.FeatureName; var featureDescription = featureObjectSetting?.Description ?? ""; }
Ivan Petrov said: it looks very expensive.
It looks funny a bit when you are worried about performance, but use LINQ queries, that are one from "safe ways" how to make code slower (depending on context from "a bit" to "thousands times" slower).
Ivan Petrov said:I know only this one: to try to find a feature definition for the element
Your original question is "Is there a way to get the feature definition for each element?", so how such information can be retrieved without analyzing every existing feature?
Small uncertainty exists here, because an element may have feature definition assigned (so it become "civil feature"), or it can be plain DGN element. To enumerate all element and to enumerate civil features are done using different code.
Ivan Petrov said:I know only this one
I do not quite understand why this code is written in this specific way. Not did not do any analysis, so I can be wrong, but subjectively it is written to consume as much memory as possible (why to create the list of entities?) and to be slow (switching context of models is not controlled).
Ivan Petrov said:Do we have some generic approach?
It depends what exactly you need and also what context exist.
Simple straightforward approach is similar to what you mentioned: enumerate existing geometric models (representing active model and attached references) and in every model, to get objects (can be Liner3dEntities, Alignments or whatever else).
Another approach, but not with the same result, is to query feature definitions, hold in every geometric model. The difference is that GeometricModel.FeatureDefinitions() method does not return definitions, used by objects, but all definitions, stored in the file. It means it can return mode definitions (when the definition is assigned to a feature and replaced by another definition assignment later).
Ivan Petrov said:it looks very expensive.
Sorry, but in software development "it looks" does not sound very professional. When there is a threat algorithm is not optimal, do performance analysis, memory allocation / GC analysis, or any other relevant benchmark.
If you are only after the Feature Definition names you could simply use an interop Property Handle method to get the "ObjectSettings" property value for each element (or use VBA).
Regards,
Mark
OpenRoads Designer 2022 R3 (10.12) | Microstation 2023 | ProjectWise CE 3.4
Mark Shamoun said:If you are only after the Feature Definition names you could simply...
Examine the ORD schema files! However, Jan comments that the overall schema is rather complex. XML files are plain text, but their content is rather indigestible. One way to clarify their content is to examine them using Bentley's ECSchema Editor.
Unfortunately, the ECSchema Editor is not a permanent member of Bentley's Software Downloads. Perhaps can tell us more about the ECSchema Editor and its availability?
Regards, Jon Summers LA Solutions
LINQ is a very good and compact way to provide an example. I do not understand why you are reacting to this in this thread - this is not the subject of our discussion. Idle talk, sorry!
Jan Ĺ legr said:t looks funny a bit when you are
Hi Jon Summers,
Jon Summers said:Unfortunately, the ECSchema Editor is not a permanent member of Bentley's Software Downloads. Perhaps Robert Hook can tell us more about the ECSchema Editor and its availability?
Interesting timing of the question...As of one year ago tomorrow (11/29/2021), I provided a High-level overview topic for "Class Editors" (anchor) that (still to the best of my knowledge) provides the best insights and most current options I could find and share. I validated (today) that each of those insight links still work and point to the latest topics and software versions available.
Thank you and HTH,Bob
Robert Hook said:each of those insight links still work and point to the latest topics and software versions available
Thanks for the reminder!
The EC Class Editor is delivered with certain OpenPlant products...