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.
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();
}
}
Hope this is useful to you!



Leave a Reply