ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / KnowledgeGraphLayerIDSet Class / ToOIDDictionary Method
Example

In This Topic
    ToOIDDictionary Method
    In This Topic
    Creates the dictionary of named object types and their corresponding objectIDs.
    Syntax
    public Dictionary<string,List<long>> ToOIDDictionary()
    Public Function ToOIDDictionary() As Dictionary(Of String,List(Of Long))

    Return Value

    Dictionary of named object types and their corresponding objectIDs.
    Example
    Get and Set a KG Layer IDSet
    var kg_layer = MapView.Active.Map.GetLayersAsFlattenedList()
                    .OfType<KnowledgeGraphLayer>().FirstOrDefault();
    if (kg_layer == null)
      return;
    
    QueuedTask.Run(() =>
    {
      //Get the existing kg layer id set and convert to a dictionary
      var layer_id_set = kg_layer.GetIDSet();
      var dict = layer_id_set.ToOIDDictionary();//Empty list means all records
    
      //Create an id set from a dictionary
      var dict2 = new Dictionary<string, List<long>>();
      dict2.Add("Enity_Or_Relate_Type_Name1", null);//Null means all records
      dict2.Add("Enity_Or_Relate_Type_Name2", new List<long>());//Empty list means all records
      dict2.Add("Enity_Or_Relate_Type_Name3", 
        new List<long>() {  3,5,9, 101, 34});//Explicit list of ids
      //dict2.Add("Enity_Or_Relate_Type_Name4",
      // new List<long>() { etc, etc });
    
      //Create the id set
      var idset = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict2);
    
      //Can be used to create a layer, link chart, append to link chart, etc...
    });
    Get the ID Set of a KG layer
    QueuedTask.Run(() =>
    {
      var idSet = kgLayer.GetIDSet();
    
      // is the set empty?
      var isEmpty = idSet.IsEmpty;
      // get the count of named object types
      var countNamedObjects = idSet.NamedObjectTypeCount;
      // does it contain the entity "Species";
      var contains = idSet.Contains("Species");
    
      // get the idSet as a dictionary of namedObjectType and oids
      var oidDict = idSet.ToOIDDictionary();
      var speciesOIDs = oidDict["Species"];
    
      // alternatively get the idSet as a dictionary of 
      // namedObjectTypes and uuids
      var uuidDict = idSet.ToUIDDictionary();
      var speciesUuids = uuidDict["Species"];
    
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.3 or higher.
    See Also