ArcGIS SDK  

Extending ArcObjects

Macros Using the Editor

In this section:

  1. Macros Using the Editor
  2. A Simple Macro Scenario
  3. Other editing scenarios that can be solved using a macro

Macros Using the Editor

Although macros don't truly extend the editor model (or ArcObjects for that matter), they are worth discussing because they are commonly used to add new editing functionality to a map document quickly.

Macros are perfect for problems that don't require much coding. However, they can still be quite complex, UIControls are macro-based and can nearly mimic a custom command or tool, but they have some drawbacks. They are hard to share with others or even between different map documents, and the code is viewable. You may want to convert your macros to commands or tools if you need to share them or if you use them with multiple map documents. Ease of debugging is a macro's biggest benefit; many commands and tools start off as macros simply because macros are so much easier to debug.


A Simple Macro Scenario

When digitizing on top of an aerial photograph, it is hard to see the edit sketch; it would be better if the edit sketch vertices and segments were larger and perhaps had a different color. Since the editing environment does not persist the sketch symbology, writing a macro is a perfect solution.

Solution

This is not a complicated scenario—and one reason why a macro solution may be appropriate. Below is a macro that modifies the edit sketch properties.

[Visual Basic 6]
Public Sub ChangeSketchSymbol()
  Dim pEditor As IEditor
  Dim pEditProperties As IEditProperties
  Dim pLineSymbol As ILineSymbol
  Dim pMarkerSymbol As ISimpleMarkerSymbol
  Dim pRgbColor As IRgbColor
  Dim pID As New UID
  
  ' Get a reference to the Editor object
  pID = "esriEditor.Editor"
  Set pEditor = Application.FindExtensionByCLSID(pID)
  Set pEditProperties = pEditor  ' Query Interface
  
  'Change the vertex size and color
  Set pMarkerSymbol = New SimpleMarkerSymbol
  Set pRgbColor = New RgbColor
  pRgbColor.Blue = 255
  pMarkerSymbol.Color = pRgbColor
  pMarkerSymbol.Size = 6
  Set pEditProperties.SketchVertexSymbol = pMarkerSymbol
  
  ' Change the sketch symbol to use a red line
  Set pLineSymbol = New SimpleLineSymbol
  Set pRgbColor = New RgbColor
  pRgbColor.Red = 255
  pLineSymbol.Color = pRgbColor
  Set pEditProperties.SketchSymbol = pLineSymbol
End Sub

Instead of having the color hardcoded, try enhancing the macro to use a color dialog box picker.


Other editing scenarios that can be solved using a macro

Another useful macro is one that applies global changes to attributes; for example, a macro that changes the case of records stored in a text property. However, macros aren't only used for simple, one-function routines; almost any command or tool can be written as a macro in VBA.

Edit Tasks

Edit tasks are similar to edit commands with one major difference: edit tasks perform a specific operation using a geometry, typically one which was created by a sketch tool. For example, the Create New Feature edit task creates new features based on the geometry created by the various sketch tools; similarly, the Select Features Using a Line edit task selects features in the map that are intersected by the edit sketch. In both cases, a geometry created by the sketch tools is used to complete an operation.

Snap Agents

Snap agents facilitate geometry placement. For example, the sketch tools make use of snap agents to enable a user to precisely place an edit sketch vertex. Because snap agents are so widely used, the editing framework manages a snapping environment—a collection of snap agents and a snap tolerance (ISnapEnvironment::SnapTolerance).

Editor Extensions

It would be easy to say that editor extensions extend the editing framework, and although this is true, so do custom commands, tools, edit tasks, and so on. Editor extensions are just another way developers can plug in to the editing model and extend it. The difference between editor extensions and other customizations is that extensions are automatically loaded and unloaded by the application; there is only ever one instance of an extension running at a time.


Back to top

See Also Extending the Editing Framework.