ArcObjects Library Reference  

EnforcingDiagramName

About the Enforcing schematic diagram name Sample

[C#]

EnforcingDiagramName.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.Schematic;

namespace EnforcingDiagramName
{
	/// <summary>
	/// EnforcingDiagramName class handling event AfterGenerateDiagram in order to prefix the name of the generated diagrams
	/// </summary>
	public class EnforcingDiagramName : ESRI.ArcGIS.Desktop.AddIns.Extension
	{

		private SchematicDatasetManager m_schematicDatasetMgr;

		public EnforcingDiagramName()
		{
		}

		protected override void OnStartup()
		{
		// Instantiate the schematic dataset manager which fires events coming from all schematic datasets
			m_schematicDatasetMgr = new SchematicDatasetManager();
			// Handles new diagram generation
			m_schematicDatasetMgr.AfterGenerateDiagram += new ISchematicDatasetEvents_AfterGenerateDiagramEventHandler(OnAfterGenerateDiagram);
		}

		protected override void OnShutdown()
		{
			m_schematicDatasetMgr.AfterGenerateDiagram -= new ISchematicDatasetEvents_AfterGenerateDiagramEventHandler(OnAfterGenerateDiagram);
			m_schematicDatasetMgr = null;
		}

		/// <summary>
		/// Occurs when a new diagram is generated
		/// </summary>
		/// <param name="schematicDiagram">Schematic diagram just generated</param>
		void OnAfterGenerateDiagram(ISchematicDiagram schematicDiagram)
		{
			// Add user name before generate diagram name
			string userName = System.Environment.UserName;

			if (State == ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled)
				schematicDiagram.Name = userName + "_" + schematicDiagram.Name;
		}

	}

}

[Visual Basic .NET]

EnforcingDiagramName.vb

Imports ESRI.ArcGIS.Schematic

''' <summary>
''' EnforcingDiagramName class handling event AfterGenerateDiagram in order to prefix the name of the generated diagrams
''' </summary>
Public Class EnforcingDiagramName
	Inherits ESRI.ArcGIS.Desktop.AddIns.Extension

	Private m_schematicDatasetMgr As SchematicDatasetManager

	Public Sub New()

	End Sub

	Protected Overrides Sub OnStartup()
		' Instantiate the schematic dataset manager which fires events coming from all schematic datasets
		m_schematicDatasetMgr = New SchematicDatasetManager()

		' Handles new diagram generation
		AddHandler m_schematicDatasetMgr.AfterGenerateDiagram, AddressOf OnAfterGenerateDiagram
	End Sub

	Protected Overrides Sub OnShutdown()
		RemoveHandler m_schematicDatasetMgr.AfterGenerateDiagram, AddressOf OnAfterGenerateDiagram
		m_schematicDatasetMgr = Nothing
	End Sub

	''' <summary>
	''' Occurs when a new diagram is generated
	''' </summary>
	''' <param name="schematicDiagram">Schematic diagram just generated</param>
	Sub OnAfterGenerateDiagram(ByVal schematicDiagram As ISchematicDiagram)
		' Add user name before diagram name
		Dim userName As String = System.Environment.UserName

		If State = ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled Then
			schematicDiagram.Name = userName + "_" + schematicDiagram.Name
		End If
	End Sub
End Class