With Pick List, users can specify predefined values from a drop down list in property definition. It is for ItemType only.The following codes are some of the basic uses of the managed APIs for Pick List.
1. To create Pick Lists:
DgnFile dgnFile = GetDgnFile(); if(null == dgnFile) return false; PickListLibrary pickListLib = PickListLibrary.Create(); if(null == pickListLib) return false; PickList pickList1 = pickListLib.AddPickList("Manufacturer", dgnFile); if(null == pickList1) return false; pickList1.AddValue("Ford"); pickList1.AddValue("BMW"); pickList1.AddValue("Benz"); PickListLibrary.SavePickListLibToDgn(dgnFile, pickListLib, false);
2. To load Pick Lists from a given DGN file:
DgnFile dgnFile = Session.Instance.GetActiveDgnFile(); PickListLibrary library = PickListLibrary.Create(); PickListLibrary.GetPickListLibFromDgn(dgnFile, library);
3. To Rename a Pick List:
PickList pickList = pickListLib.GetPickListByName("Manufacturer"); if(null != pickList) pickList.Name = "Manufacturer2";
4. To Delete a Pick List value and a Pick List:
PickList pickList = pickListLib.GetPickListByName("Manufacturer"); if(null == pickList) return false; pickList.RemoveValue("Ford"); pickListLib.RemovePickListByName("Manufacturer"));
To use these APIs, we need reference Bentley.DgnPlatformNET.dll and use namespace Bentley.DgnPlatformNET;
More examples are coming soon.
It's coming soon.
Great.
Great!
This did not work in previos realeses.
My existing code works just fine without change.
/Krister
I think the auto casting Mangesh describes will work. It just wasn't obvious that this would happen - so, good to know. Thanks to you both for your help.
Colin's suggestion to test library.GetPickListCount() will work. Thanks.
Hi, Mangesh. Thanks. I think what Mark want is he likes such methods: AddValue(int value), AddValue(double value), AddValue(bool value). We only have method AddValue(System::String^ value), while user may has an int variant, if AddValue(int value) exists, he can directly input an int variant, and won't do cast from String to int in code.
Excellent examples!
I would like to see something similar for C++ in the MicroStationAPI.
Hi Mark,
First of all, thanks for feedback. It's encouraging us for writing more blogs.
Now your questions:
1. Numeric Support in Pick List: Yes it's available today via auto casting. For e.g. If you have picklist with following values: 15.43, ABC, 18, XYZ.
If you assign this picklist to an ItemType property with type:
a. String: Picklist value will be: 15.43, ABC, 18, XYZ.
b. Int: Picklist value will be: 15, 18
c. Numeric(double): Picklist value will be: 15.43, 18.00
This should handle Unit as well.
2. Validate library
-- Whatever Colin mention is that something you are looking for. Or are you looking for some other validation.
Thank you very much for your feedback, Mark.
For AddValue method, I think your suggestion is very useful, I'd like to add those different types in the future.
For "PickListLibrary.GetPickListLibFromDgn(dgnFile, library);", we can call "library.GetPickListCount()" to check if there are Pick Lists in the library.
"PickListLibrary.GetPickListLibFromDgn(dgnFile, library);" just loads the data from dgnFile. if we have added values into library and want to save them to dgnFile, we need call "PickListLibrary.SavePickListLibToDgn(dgnFile, library, false);"
Thanks. I can use this. I have a couple of question. The create example shows adding values as type string. Will AddValue handle different types - double, int, bool? And in step 2 it's probably a good idea to validate library to make sure we got something usable. Any suggestions on the best way to approach this?