This document is archived and information here might be outdated.  Recommended version.


Clear NAClass Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Clear NAClass Snippet

Clears all features previously stored in the specified NAClass.

[C#]
///<summary>Clears all features previously stored in the specified NAClass.</summary>
///  
///<param name="naWindow">An INAWindow interface.</param>
///<param name="activeView">An IActiveView interface.</param>
///<param name="naClassName">A System.String that is the name of the NAClass to be cleared. Example: "Barriers".</param>
///  
///<remarks></remarks>
public static void ClearNAClass(ESRI.ArcGIS.NetworkAnalystUI.INAWindow naWindow, ESRI.ArcGIS.Carto.IActiveView activeView, System.String naClassName)
{
  ESRI.ArcGIS.NetworkAnalystUI.INAWindowCategory naWindowCategory=naWindow.get_CategoryByNAClassName(naClassName);
  naWindow.DelayEvents(naWindowCategory, true);
  naWindow.DelayWindowUpdates(true);

  ESRI.ArcGIS.NetworkAnalyst.INALayer naLayer=naWindow.ActiveAnalysis;
  ESRI.ArcGIS.NetworkAnalyst.INAContext naContext=naLayer.Context;
  ESRI.ArcGIS.NetworkAnalyst.INamedSet namedSet=naContext.NAClasses;
  System.Object theObject=namedSet.get_ItemByName(naClassName);
  ESRI.ArcGIS.NetworkAnalyst.INAClass naClass=theObject as ESRI.ArcGIS.NetworkAnalyst.INAClass;

  if (naClass != null) naClass.DeleteAllRows();

  naWindow.DelayWindowUpdates(false);
  naWindow.DelayEvents(naWindowCategory, false);
  activeView.Refresh();
}
[Visual Basic .NET]
'''<summary>Clears all features previously stored in the specified NAClass.</summary>
'''  
'''<param name="naWindow">An INAWindow interface.</param>
'''<param name="activeView">An IActiveView interface.</param>
'''<param name="naClassName">A System.String that is the name of the NAClass to be cleared. Example: "Barriers".</param>
'''  
'''<remarks></remarks>
Public Shared Sub ClearNAClass(ByVal naWindow As ESRI.ArcGIS.NetworkAnalystUI.INAWindow, ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal naClassName As System.String)

  Dim naWindowCategory As ESRI.ArcGIS.NetworkAnalystUI.INAWindowCategory=naWindow.CategoryByNAClassName(naClassName)
  naWindow.DelayEvents(naWindowCategory, True)
  naWindow.DelayWindowUpdates(True)

  Dim naLayer As ESRI.ArcGIS.NetworkAnalyst.INALayer=naWindow.ActiveAnalysis
  Dim naContext As ESRI.ArcGIS.NetworkAnalyst.INAContext=naLayer.Context
  Dim namedSet As ESRI.ArcGIS.NetworkAnalyst.INamedSet=naContext.NAClasses
  Dim theObject As System.Object=namedSet.ItemByName(naClassName)
  Dim naClass As ESRI.ArcGIS.NetworkAnalyst.INAClass=CType(theObject, ESRI.ArcGIS.NetworkAnalyst.INAClass) ' Explicit Cast

  If Not (naClass Is Nothing) Then

   naClass.DeleteAllRows()

  End If

  naWindow.DelayWindowUpdates(False)
  naWindow.DelayEvents(naWindowCategory, False)
  activeView.Refresh()

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.NetworkAnalyst
  • ESRI.ArcGIS.NetworkAnalystUI