ArcObjects Library Reference  

Autorefresh

About the Schematic diagram auto refresh Sample

[C#]

Autorefresh.cs

// Copyright 2011 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions at <your ArcGIS install location>/DeveloperKit10.1/userestrictions.txt.
// 

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Schematic;
using ESRI.ArcGIS.SchematicControls;
using ESRI.ArcGIS.SchematicUI;

namespace Autorefresh
{
	public class Autorefresh : ESRI.ArcGIS.Desktop.AddIns.Button
	{
		IApplication m_application;                        // Valid upon create
		ISchematicInMemoryDiagram m_schematicInMemoryDiagram;
		ISchematicTarget m_schematicTarget = null;
		protected FormAutoRefresh m_formAuto;

		public Autorefresh()
		{
			m_application = ArcMap.Application;
		}

		protected override void OnClick()
		{
			if (m_schematicTarget != null && m_schematicTarget.SchematicTarget != null && m_schematicTarget.SchematicTarget.IsEditingSchematicDiagram())
			{
				if (m_schematicInMemoryDiagram == null)
					m_schematicInMemoryDiagram = m_schematicTarget.SchematicTarget.SchematicInMemoryDiagram;

				if (m_schematicInMemoryDiagram != null)
				{
					if (m_formAuto == null)
					{
						m_formAuto = new FormAutoRefresh();
						try
						{
							m_formAuto.InitializeSecond();
							m_formAuto.InitializeMinute();
						}
						catch (Exception e)
						{
							System.Windows.Forms.MessageBox.Show(e.Message);
						}
					}
					m_formAuto.SetSchematicInmemoryDiagram(m_schematicInMemoryDiagram);
					m_formAuto.Appli = m_application;

					m_formAuto.Show();
				}
			}
		}

		protected override void OnUpdate()
		{
			if (m_schematicTarget == null)
			{
				IExtension extention = null;
				IExtensionManager extensionManager;

				extensionManager = (IExtensionManager)m_application;
				for (int i = 0; i < extensionManager.ExtensionCount; i++)
				{
					extention = extensionManager.get_Extension(i);
                    if (extention.Name.ToLower() == "esri schematic extension")
                        break;
				}

				if (extention != null)
				{
					SchematicExtension schematicExtension = extention as SchematicExtension;
					m_schematicTarget = schematicExtension as ISchematicTarget;
				}
			}

			if (m_schematicTarget != null)
			{
				ISchematicLayer schematicLayer;
				schematicLayer = m_schematicTarget.SchematicTarget;

				if (schematicLayer == null)
				{
					Enabled = false;
					if (m_formAuto != null) m_formAuto.SetAutoOff(true);
				}
				else if (schematicLayer.IsEditingSchematicDiagram())
					Enabled = true;
				else
				{
					Enabled = false;
					if (m_formAuto != null) m_formAuto.SetAutoOff(true);
				}
			}
			else
			{
				Enabled = false;
				if (m_formAuto != null) m_formAuto.SetAutoOff(true);
			}
		}
	}
}


[Visual Basic .NET]

Autorefresh.vb

' Copyright 2011 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions at <your ArcGIS install location>/DeveloperKit10.1/userestrictions.txt.
' 

Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Schematic
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.SchematicControls
Imports ESRI.ArcGIS.SchematicUI

Public Class Autorefresh
	Inherits ESRI.ArcGIS.Desktop.AddIns.Button

  Private m_application As ESRI.ArcGIS.Framework.IApplication
	Private m_schematicTarget As ISchematicTarget
	Private m_schematicInMemoryDiagram As ISchematicInMemoryDiagram
	Protected m_formAutorefresh As FormAutorefresh

	Public Sub New()
		m_application = My.ArcMap.Application
	End Sub

	Protected Overrides Sub OnClick()
		If m_schematicTarget IsNot Nothing AndAlso m_schematicTarget.SchematicTarget IsNot Nothing AndAlso m_schematicTarget.SchematicTarget.IsEditingSchematicDiagram() Then
			If m_schematicInMemoryDiagram Is Nothing Then
				m_schematicInMemoryDiagram = m_schematicTarget.SchematicTarget.SchematicInMemoryDiagram
			End If

			If m_schematicInMemoryDiagram IsNot Nothing Then
				If (m_formAutorefresh Is Nothing) Then
					m_formAutorefresh = New FormAutorefresh()
					Try
						m_formAutorefresh.InitializeSecond()
						m_formAutorefresh.InitializeMinute()
					Catch e As Exception
						System.Windows.Forms.MessageBox.Show(e.Message)
					End Try
				End If
			End If

			m_formAutorefresh.SetSchematicInmemoryDiagram(m_schematicInMemoryDiagram)
			m_formAutorefresh.Appli(m_application)
			m_formAutorefresh.Show()

		End If
	End Sub

	Protected Overrides Sub OnUpdate()

		If m_schematicTarget Is Nothing Then
			Dim extention As ESRI.ArcGIS.esriSystem.IExtension
			Dim extensionManager As ESRI.ArcGIS.esriSystem.IExtensionManager

			extention = Nothing
			extensionManager = m_application
			For i As Integer = 0 To extensionManager.ExtensionCount - 1
				extention = extensionManager.Extension(i)
                If extention.Name.ToLower() = "esri schematic extension" Then
                    Exit For
                End If
			Next

			If extention IsNot Nothing Then
				Dim schematicExtension As SchematicExtension
				schematicExtension = TryCast(extention, SchematicExtension)
				m_schematicTarget = TryCast(schematicExtension, ISchematicTarget)
			End If
		End If

		If m_schematicTarget IsNot Nothing Then
			Dim schematicLayer As ISchematicLayer
			schematicLayer = m_schematicTarget.SchematicTarget

			If schematicLayer Is Nothing Then
				Enabled = False
				If (m_formAutorefresh IsNot Nothing) Then m_formAutorefresh.SetAutoOff(True)
			ElseIf schematicLayer.IsEditingSchematicDiagram() Then
				Enabled = True
			Else
				Enabled = False
				If (m_formAutorefresh IsNot Nothing) Then m_formAutorefresh.SetAutoOff(True)
			End If
		Else
			Enabled = False
			If (m_formAutorefresh IsNot Nothing) Then m_formAutorefresh.SetAutoOff(True)
		End If

	End Sub
End Class