Verify if a FDO feature attribute is ’empty’ using Map 3D API

By Partha Sarkar

In the screenshot below, we can see the Name attribute of two features are Empty. In my FDO data set I have hundreds of thousands of features and I would like to find out if any attribute is empty (i.e. there is no Value) for selected features in Map 3D using API.

FDO_1

 

 

Here is a relevant C# code snippet in Map 3D which will check if the “Name” attribute of any selected Feature is Empty and if it is Empty, it will show the Feature ID and a message that “Name Attribute is Empty “ at the Map 3D command Line.

 

AcMapMap currentMap = AcMapMap.GetCurrentMap();
MgLayerCollection layers = currentMap.GetLayers();
 
PromptSelectionResult selResult = ed.GetSelection();
if (selResult.Status == PromptStatus.OK)
{
  SelectionSet selSet = selResult.Value;
  MgSelectionBase selectionBase = AcMapFeatureEntityService.GetSelection(selSet);
 
  //Ensure user selected a feature
  MgLayerBase myLayer = null;
  foreach (MgLayerBase layer in selectionBase.GetLayers())
  {
    if (layer.Name == "API_Poly_Objects")   // change to your own layer name
    {
      myLayer = layer;
      break;
    }
  }
  if (myLayer == null)
  {
    ed.WriteMessage("No Feature is selected from the designated Layer ! ");
    return;
  }
 
  //get the properties 
  MgFeatureReader reader = selectionBase.GetSelectedFeatures(myLayer, myLayer.FeatureClassName, false);
  try
  {
    while (reader.ReadNext())
    {
      string featureName = reader.GetString("Name");  // this this just a demo, change this according to your data field
      if (featureName == "")
      {
        Int32 FeatureID = reader.GetInt32("ID");  // this this just a demo, change this according to your data field
        ed.WriteMessage("n Feature ID :" + FeatureID.ToString() + " Name Attribute is Empty ");
      }
    }
  }
  finally
  {
    reader.Close();
  }
}

 

FDO_2

Hope this is useful to you!

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading