HOW TO
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.
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.
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
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.
Get help from ArcGIS experts
Download the Esri Support App