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.
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?
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);"