My goal is to collect instances of a given Item Type in a DGN model. To achieve that I must first get an EC schema from the active DGN file or model. My attempts in C# fail...
FindInstancesScope scope = FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnModel(), new FindInstancesScopeOption ()); IECSchema schema = DgnECManager.Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);
schemaName is something like MasterPlanner, where MasterPlanner is the name of an Item Type library defined in the active DGN file. What am I doing wrong?
schemaName
Hi Jon,
Jon Summers said:schemaName is something like MasterPlanner
Are you sure about the schema name? How the schema was created? When schema comes from Item Type GUI, so it's not general EC schema (created using Class Editor or by developer through EC API), it's named DgnCustomItemTypes_<ItemTypeLibraryName>.masterversion.minorversion.
Use "ecx schema list" to check how schemas in your DGN file are named to ensure you do not pass not existing schema name to search method.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Jan Šlegr said:Use "ecx schema list"
I had forgotten about that command!
Unfortunately, LocateSchemaInScope still fails when using the full schema name obtained from ECX.
LocateSchemaInScope
Is there no way to obtain that schema name programmatically? It doesn't make sense for us to have to write a function that generates a string that MicroStation creates internally. We don't know the algorithm that MicroStation uses, and whatever we may come up with will be hard to maintain as MicroStation evolves.
Regards, Jon Summers LA Solutions
Jon Summers said:Unfortunately, LocateSchemaInScope still fails when using the full schema name obtained from ECX.
What do you use as "full name"? With or without version info? I think without the version is what should be passed.
Can you share simple design file with the schema you want to find?
Regards,
Jan Šlegr said:Can you share simple design file with the schema
MasterPlanner schema.dgn
Jan Šlegr said:What do you use as "full name"? With or without version info?
I've tried various permutations of the schema name, with and without the version info.
Jon Summers said:What am I doing wrong?
Based on some testing, I think the problem is how you define the scope. This code works fine with your design file:
FindInstancesScope scope = FindInstancesScope.CreateScope(Session.Instance.GetActiveDgnFile(), new FindInstancesScopeOption(DgnECHostType.All, false)); DgnECManager manager = DgnECManager.Manager; IECSchema schema = manager.LocateSchemaInScope(scope, "DgnCustomItemTypes_MasterPlanner_1_0", 1, 0, SchemaMatchType.Latest);
Because we discussed also schema naming, this is code how to obtain names of schemas stored in the file:
IEnumerable<string> schemas = manager.DiscoverSchemas(Session.Instance.GetActiveDgnFile(), ReferencedModelScopeOption.All, false);
Answer Verified By: Jon Summers
Jan Šlegr said:I think the problem is how you define the scope
Using FindInstancesScopeOption(DgnECHostType.All, false) works. I had tried both the following with no success...
FindInstancesScopeOption(DgnECHostType.All, false)
FindInstancesScopeOption(DgnECHostType.Model, false) FindInstancesScopeOption(DgnECHostType.File, false)
But an EC Schema is stored in the DGN file, so while does DgnECHostType.All work, yet DgnECHostType.File and DgnECHostType.Model don't work?
DgnECHostType.All
DgnECHostType.File
DgnECHostType.Model
Jon Summers said:yet DgnECHostType.File and DgnECHostType.Model don't work?
That's good question, but I have no idea about an answer ;-)
Maybe more narrow specifications (File, Model...) makes sense when not schema, but specific EC data valid and stored in particular area, are searched.
I've published an example Viz Studio project Item Instance Collector. Your advice helped me to write that project!
Is there any updates on this to collect instances of item types attached to element?
Hi Samuel,
please do not extend (reopen) this 4 years old discussion.
It is not clear how your question (to find items attached to an element) relates to original topic of this discussion (how to find EC schema).
Please post new question and explain your issue clearly.