ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / KnowledgeGraphLayer Class / GetIDSet Method
Example Version

GetIDSet Method
Gets the current KnowledgeGraphLayerIDSet for this Knowledge Graph layer. That is the set of Named Object types and their corresponding set of records. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
public KnowledgeGraphLayerIDSet GetIDSet()

Return Value

Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
Remarks
If the KnowledgeGraphLayer resides in a Map and an an empty list for a Named Object type is returned, then all records for that Named Object are present.

If the KnowledgeGraphLayer resides in a Link Chart (a map of MapType.LinkChart) and an empty list for a Named Object type is returned, then no records for that Named Object are present.

If an empty dictionary is returned, then no Named Object types and records are present in the layer.
Example
Create a LinkChart from a subset of an existing LinkChart IDSet
var map = MapView.Active.Map;
if (map.MapType != MapType.LinkChart)
  return;

// find the KG layer
var kgLayer = map.GetLayersAsFlattenedList().OfType<KnowledgeGraphLayer>().FirstOrDefault();
if (kgLayer == null)
  return;

// find the first LinkChartFeatureLayer in the KG layer
var lcFeatureLayer = kgLayer.GetLayersAsFlattenedList().OfType<LinkChartFeatureLayer>().FirstOrDefault();
if (lcFeatureLayer != null)
  return;

QueuedTask.Run(() =>
{
  // get the KG
  var kg = kgLayer.GetDatastore();

  // get the ID set of the KG layer
  var idSet = kgLayer.GetIDSet();

  // get the named object type in the KG that the LinkChartFeatureLayer represents
  var typeName = lcFeatureLayer.GetTypeName();
  // if there are items in the ID Set for this type
  if (idSet.Contains(typeName))
  {
    // build a new ID set containing only these records
    var dict = idSet.ToOIDDictionary();
    var oids = dict[typeName];

    var newDict = new Dictionary<string, List<long>>();
    newDict.Add(typeName, oids);

    var newIDSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, newDict);

    // now create a new link chart using just this subset of records
    MapFactory.Instance.CreateLinkChart("subset LinkChart", kg, newIDSet);
  }
});
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