About the Customizing schematic feature removal events Sample
[C#]
FeatureRemovalMgmt.cs
using ESRI.ArcGIS.Schematic; namespace SchematicFeatureRemoveCS { public class FeatureRemovalMgmt : ESRI.ArcGIS.Desktop.AddIns.Extension { private SchematicDatasetManager m_SchemDatasetMgr; private const string DiagramClassName = "InsidePlants"; private const string AttributeNameObjectID = "Object_Id"; private const string TableNameNodes = "Inside_Nodes"; private const string TableNameLinks = "Inside_Links"; private const string SampleDatasetName = "RemovalSample_Schematic"; protected override void OnStartup() { m_SchemDatasetMgr = new SchematicDatasetManager(); m_SchemDatasetMgr.BeforeRemoveFeature += new ISchematicDatasetEvents_BeforeRemoveFeatureEventHandler(OnBeforeRemoveFeature); } protected override void OnShutdown() { m_SchemDatasetMgr.BeforeRemoveFeature -= OnBeforeRemoveFeature; m_SchemDatasetMgr = null; base.OnShutdown(); } void OnBeforeRemoveFeature(ISchematicInMemoryFeature inMemoryFeature, ref bool canRemove) { if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled) return; ESRI.ArcGIS.Geodatabase.IDataset esriData = (ESRI.ArcGIS.Geodatabase.IDataset)inMemoryFeature.SchematicDiagram.SchematicDiagramClass.SchematicDataset; // Remove only elements contained in a specific Schematic dataset if (esriData.Name != SampleDatasetName) return; // Remove only elements contained in a specific type of diagram if (inMemoryFeature.SchematicDiagram.SchematicDiagramClass.Name != DiagramClassName) return; canRemove = false; // can't remove SubStation if (inMemoryFeature.SchematicElementClass.Name == "InsidePlant_SubStation") return; ISchematicDiagramClass schemDiagramClass; schemDiagramClass = (ISchematicDiagramClass)inMemoryFeature.SchematicDiagram.SchematicDiagramClass; // For this specific diagram type, we retrieve the datasource // and the tables where the elements are stored ISchematicDataSource schemDataSource = schemDiagramClass.SchematicDataSource; string tableName = ""; switch (inMemoryFeature.SchematicElementClass.SchematicElementType) { case esriSchematicElementType.esriSchematicNodeType: tableName = TableNameNodes; break; case esriSchematicElementType.esriSchematicLinkType: tableName = TableNameLinks; break; case esriSchematicElementType.esriSchematicDrawingType: return; break; } // Retrieve Feature Workspace ESRI.ArcGIS.Geodatabase.IWorkspace esriWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)schemDataSource.Object; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace esriFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)esriWorkspace; // Get Attributes values ISchematicAttributeContainer schemAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass; ISchematicAttributeContainer schemFatherAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass.Parent; if ((!(schemAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null) || !(schemFatherAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null))) { int indField = inMemoryFeature.Fields.FindFieldByAliasName(AttributeNameObjectID); int OID = int.Parse(inMemoryFeature.get_Value(indField).ToString(), System.Globalization.NumberStyles.Integer); //Get table and row ESRI.ArcGIS.Geodatabase.ITable esriTable = esriFeatureWorkspace.OpenTable(tableName); ESRI.ArcGIS.Geodatabase.IRow esriRow = esriTable.GetRow(OID); // When the row is identified in the table, it is deleted and // the CanRemove returns True so that the associated // schematic element is graphically removed from the active diagram if (!(esriRow == null)) { esriRow.Delete(); canRemove = true; } } } } }
[Visual Basic .NET]
FeatureRemovalMgmt.vb
Imports ESRI.ArcGIS.Schematic Public Class FeatureRemovalMgmt Inherits ESRI.ArcGIS.Desktop.AddIns.Extension Private m_SchemDatasetMgr As SchematicDatasetManager Private Const DiagramClassName As String = "InsidePlants" Private Const AttributeNameObjectID As String = "Object_Id" Private Const TableNameNodes As String = "Inside_Nodes" Private Const TableNameLinks As String = "Inside_Links" Private Const SampleDatasetName As String = "RemovalSample_Schematic" Protected Overrides Sub OnStartup() m_SchemDatasetMgr = New SchematicDatasetManager() AddHandler m_SchemDatasetMgr.BeforeRemoveFeature, AddressOf OnBeforeRemoveFeature End Sub Protected Overrides Sub OnShutdown() RemoveHandler m_SchemDatasetMgr.BeforeRemoveFeature, AddressOf OnBeforeRemoveFeature m_SchemDatasetMgr = Nothing End Sub Sub OnBeforeRemoveFeature(ByVal inMemoryFeature As ISchematicInMemoryFeature, ByRef canRemove As Boolean) If (State <> ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled) Then Return Dim esriData As ESRI.ArcGIS.Geodatabase.IDataset = CType(inMemoryFeature.SchematicDiagram.SchematicDiagramClass.SchematicDataset, ESRI.ArcGIS.Geodatabase.IDataset) ' Remove only elements contained in a specific Schematic dataset If (esriData.Name <> SampleDatasetName) Then Return ' Remove only elements contained in a specific type of diagram If (inMemoryFeature.SchematicDiagram.SchematicDiagramClass.Name <> DiagramClassName) Then Return canRemove = False ' can't remove SubStation If (inMemoryFeature.SchematicElementClass.Name = "InsidePlant_SubStation") Then Return Dim schemDiagramClass As ISchematicDiagramClass schemDiagramClass = CType(inMemoryFeature.SchematicDiagram.SchematicDiagramClass, ISchematicDiagramClass) ' For this specific diagram type, we retrieve the datasource ' and the tables where the elements are stored Dim schemDataSource As ISchematicDataSource = schemDiagramClass.SchematicDataSource Dim tableName As String = "" Select Case (inMemoryFeature.SchematicElementClass.SchematicElementType) Case esriSchematicElementType.esriSchematicNodeType tableName = TableNameNodes Case esriSchematicElementType.esriSchematicLinkType tableName = TableNameLinks Case esriSchematicElementType.esriSchematicDrawingType Return End Select ' Retrieve Feature Workspace Dim esriWorkspace As ESRI.ArcGIS.Geodatabase.IWorkspace = CType(schemDataSource.Object, ESRI.ArcGIS.Geodatabase.IWorkspace) Dim esriFeatureWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace = CType(esriWorkspace, ESRI.ArcGIS.Geodatabase.IFeatureWorkspace) ' Get Attributes values Dim schemAttribCont As ISchematicAttributeContainer = CType(inMemoryFeature.SchematicElementClass, ISchematicAttributeContainer) Dim schemFatherAttribCont As ISchematicAttributeContainer = CType(inMemoryFeature.SchematicElementClass.Parent, ISchematicAttributeContainer) If ((schemAttribCont.GetSchematicAttribute(AttributeNameObjectID, False) IsNot Nothing) OrElse (schemFatherAttribCont.GetSchematicAttribute(AttributeNameObjectID, False) IsNot Nothing)) Then Dim indField As Integer = inMemoryFeature.Fields.FindFieldByAliasName(AttributeNameObjectID) Dim OID As Integer = Integer.Parse(inMemoryFeature.Value(indField).ToString(), System.Globalization.NumberStyles.Integer) 'Get table and row Dim esriTable As ESRI.ArcGIS.Geodatabase.ITable = esriFeatureWorkspace.OpenTable(tableName) Dim esriRow As ESRI.ArcGIS.Geodatabase.IRow = esriTable.GetRow(OID) ' When the row is identified in the table, it is deleted and ' the CanRemove returns True so that the associated ' schematic element is graphically removed from the active diagram If (esriRow IsNot Nothing) Then esriRow.Delete() canRemove = True End If End If End Sub End Class