is it possible (and if yes, is there an example available) to define ECProperty as enum type, so the only predefined values will be possible to choose from MicroStation GUI when the property is edited? I guess a relationship to some class with array of values can be the solution, but was not able to create such schema so far.
Jan Šlegr said:is it possible (and if yes, is there an example available) to define ECProperty as enum type
Hidden in MicroStation CONNECT Update 7 are Pick Lists. In that Update I don't think that they were intended to be publicly visible. Perhaps we'll see more in Update 8.
See Krister Surell's post about Picklists and C#. He obviously spotted something that I missed!
AFAIK all ECProperties (and hence Item Types) are ultimately XML data. There are structures such as ValueMaps (see the delivered EC Schemas) that could be interpreted as a C#/C++ enum, but there's no way that I know of to convert a ValueMap to an enum at run-time.
Regards, Jon Summers LA Solutions
I'm relatively certain the new "pick lists" are only usable with Item Types (created in MicroStation's Item Types dialog), not general ECSchemas. I could be wrong.
However ECSchemas have for years supported custom attributes which behave like enums and are displayed to the user as a pick list in a drop-down when editing property values. For example, to define a "widget size" property with allowable values of Small, Medium, and Large:
<ECProperty propertyName="WidgetSize" typeName="int" displayLabel="Widget Size">
Thanks, Jon Summers. I always appreciate your time and expertise. Unfortunately for me I'm working in SS3 and don't have experience with C#/C++ (yet?), so I'm constrained to find a solution via the XML schema and VBA if necessary.
Thanks, Paul! This gets me 85% of the way there, which is enough for a working solution for my project. What I'm now hacking away at is to define a similar structure to a "ValueMap" which enables me to define their "Value" as a string as opposed to an integer, so that when users enter in a value not predefined, it will not error out with "ECStandardValues TypeConverter cannot convert from System.String". Something more like:
<ECProperty propertyName="WidgetSize" typeName="string" displayLabel="Widget Size">
I've been trying that, and it seems to work in the Bentley Class Editor, but when I apply the schema to an element the "Pick List" functionality isn't working.
chrisedjohn said:I'm constrained to find a solution via the XML schema and VBA
If you want to work with XML using VBA, then you need an XML parser. Microsoft's MSXML works with VBA.
It's a low-level API. You load a file (e.g. an EC Schema) into a document object model (DOM). You use low-level MSXML functions to work with the DOM: for example, to query for a value or values. To make that work you have to have a good understand of the XML query language and how that works to find one or more nodes. It's best to use a tool such as XMLSpy to understand the query syntax.
What you're attempting with MicroStation V8i SSx and VBA will be challenging.
You can avoid the hassle with XML and VBA by using C# to create a COM DLL. C# lets you create a COM DLL, which you then call from VBA. You design the interface to be implemented in the DLL: for example,
GetWidgetSize (ByVal index As Long)
I recommend this because C# has excellent XML query and construction tools available, such as Language Embedded Query (LINQ). Take a look at LINQPad, which provides some wonderful examples.
Please consider starting a new thread!
This relates to what I have been asking in this thread.
It is possible (and quite easy) to create PickLists for ItemTypes but the lists are strings only. I you attach such a PickList to an Int or a Double property you will get that "ECStandardValues TypeConverter cannot convert from System.String" message.
Bentleys answer was to use the PickListHandler class (which I have not succeded to do). I think that this kind of basic data type conversion should be done automatically. If not, the PicklLists should have a data type so they can only be attached to a matching property. Otherwise you will have a dgn file that needs some application to work since the pick lists are stored in the file but not the handler.
Owner consultant at Surell Consulting AB