Basic examples for managed APIs of Pick List

Introduction

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.

Basic examples:

  1. To create Pick Lists
  2. To load Pick Lists from a given DGN file
  3. To Rename a Pick List
  4. To Delete a Pick List value and a 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.

Anonymous