more arcobjects... try it.. create a button in ArcMap
OK... here are a few steps you follow in VB6 or if you want... even VB.NET.
Firstly when you start Visual Studio for a new project... choose to create a DLL... cause this is gonna be compiled as a DLL... not EXE okei !!!
Add this code:
Private m_pApp As esriFramework.IApplication
Private Sub ICommand_OnCreate(ByVal hook As Object)
If TypeOf hook Is esriArcMapUI.IMxApplication Then
Set m_pApp = hook
Set m_pMxDoc = m_pApp.Document
' Get the extension
Dim u As New esriSystem.UID
u.Value = "CmdToolbarExt.SampleExtension"
Set m_pExt = m_pApp.FindExtensionByCLSID(u)
End If
End Sub
Know what its doing?? Its to create a Command in ArcMap and reference its interface. This ICommand interface determines behaviour and properties for simple commands in ArcMap... like buttons or menus. This interface also controls command properties like caption, name, category and status bar message. So what is happening with the above code??
Its actually starting something... when the command in instantiated... or when ArcMap is launched... it provides a hook or a connection to the ArcMap application. Its also important to see what type of object is passed by the hook... in this case its to ArcMap (IMxApplication).
Next add this:
Private Property Get ICommand_Enabled() As Boolean
If m_pExt.State = esriESEnabled Then
ICommand_Enabled = True
Else
ICommand_Enabled = False
End If
End Property
This is kinda straightforward... its actually specifying when the command is gonna be enabled.
Now add this:
Private Sub ICommand_OnClick()
' Zoom to the full extent
Dim pActiveView As esriCarto.IActiveView
Set pActiveView = m_pMxDoc.ActiveView
pActiveView.Extent = pActiveView.FullExtent
pActiveView.Refresh
End Sub
Private Property Get ICommand_Caption() As String
ICommand_Caption = "SampleCommand (zoom to full extent)"
End Property
Private Property Get ICommand_Name() As String
ICommand_Name = "ExtendingArcObjects_SampleCommand"
End Property
This also is self explanatory... when the command is clicked... there is an action or method.... in this case... its zooming to full extent. The Caption and Name is set with the following codes right after. Simple huh??
Now... compile this as DLL and then add it into ArcMap Customize function and you already have a working command.
Easy or not??
Labels: GIS Malaysia Tony Joseph ESRI
1 Comments:
not
Post a Comment
Subscribe to Post Comments [Atom]
<< Home