English

How To: Create a line symbol with a marker placed at the mid-point

Summary

A line symbol with a marker placed at the mid-point can be created using ArcObjects. Once the style has been created, the properties of both the line and marker can be modified using the Symbol Property Editor dialog. The only property that cannot be altered is the position of the marker.

Procedure

  1. Start ArcMap.
  2. Open the Visual Basic Editor. In ArcMap, select Tools > Macros > Visual Basic Editor.
  3. Expand Project.mxt in the Project Explorer window, and select ArcMap Objects > ThisDocument. Then, right-click and select View Code.
[O-Image] Visual Basic Project  Explorer
Note:
Code in the Project's ThisDocument code module will only run in the current map document. If you want to store the code in all your map documents, open the Normal.mxt ThisDocument code module instead.
  1. Copy the following code into the code module. Substitute the path to the output style as well as the desired font and pattern for the marker.
    Private pCartoRGB As IRgbColor
    Private pMarkerRGB As IRgbColor
    Private pStyItem As IStyleGalleryItem
    Private pStyGall As IStyleGallery
    Private pStyStor As IStyleGalleryStorage
    Private pMultiLine As IMultiLayerLineSymbol
    Private pCartoLine As ICartographicLineSymbol
    Private pLineDec As ILineDecoration
    Private pLineProps As ILineProperties
    Private pLineDecElem As ISimpleLineDecorationElement
    Private pCharMarker As ICharacterMarkerSymbol
    Private pMrkFont As StdFont
    
    Sub ToArrowCentered()
    'Create a new style file
      Set pStyGall = New StyleGallery
      Set pStyStor = pStyGall
    'Change the path and name of the output style if needed
      pStyStor.TargetFile = "D:\MidArrow.style"
    
    'Create the new item for the style
      Set pStyItem = New StyleGalleryItem
      pStyItem.Name = "To Arrow"
      pStyItem.Category = "Mid Point"
    
    'Create the line symbol
      Set pMultiLine = New MultiLayerLineSymbol
      Set pCartoLine = New CartographicLineSymbol
      Set pLineProps = pCartoLine
      'Properties for the Cartographic Line Layer
      Set pCartoRGB = New RgbColor
      With pCartoRGB
        .Red = 0
        .Green = 0
        .Blue = 0
      End With
      With pCartoLine
        .Color = pCartoRGB
        .Width = 1
      End With
      'Properties for the Line Decoration (Arrow)
      Set pMarkerRGB = New RgbColor
      With pMarkerRGB
        .Red = 255
        .Green = 0
        .Blue = 0
      End With
      Set pCharMarker = New CharacterMarkerSymbol
      Set pMrkFont = New StdFont
      With pMrkFont
        .Name = "ESRI Arrowhead"
      End With
      With pCharMarker
        .Angle = 0 'Set the angle to the desired rotation value
        .CharacterIndex = 63
        .Color = pMarkerRGB
        .Font = pMrkFont
        .Size = 12
      End With
      Set pLineDecElem = New SimpleLineDecorationElement
      With pLineDecElem
        .AddPosition 0.5
        .MarkerSymbol = pCharMarker
        .PositionAsRatio = True
        .Rotate = True
      End With
      Set pLineDec = New LineDecoration
      pLineDec.AddElement pLineDecElem
      Set pLineProps.LineDecoration = pLineDec
      'Add it to the MultiLayer Line
      pMultiLine.AddLayer pCartoLine
      pStyItem.Item = pMultiLine
      pStyGall.AddItem pStyItem
    'Change the path and name of the output style if needed
      pStyStor.RemoveFile "D:\MidArrow.style"
    End Sub
  2. Close the Visual Basic Editor.
  3. Run the code.
  1. Click Tools > Macros > Macros to display the Macros dialog box.
  2. Select a macro and click Run.
  1. Use the Style References dialog, available from the Tools menu, to add the newly created styleset into ArcMap.
[O-Image] Style References dialog
Note:
If necessary, use the 'Add' button to browse to the location of the file. The line symbol is now available for both data and graphic elements.