И попробуй этот
Sub AddRandomPointElements()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pGC As IGraphicsContainer
Set pGC = pMxDoc.ActiveView
Dim pGCS As IGraphicsContainerSelect
Set pGCS = pGC
Dim pEnumFeat As IEnumFeature
Set pEnumFeat = pMxDoc.FocusMap.FeatureSelection
Randomize
Dim pFeat As IFeature
Set pFeat = pEnumFeat.Next
Do Until pFeat Is Nothing
If TypeOf pFeat.Shape Is IPolyline Then
Dim lPoints As Long
lPoints = 10 'This is the number of random points to generate
Dim pGrpElement As IGroupElement
Set pGrpElement = New GroupElement
Dim l As Long
For l = 0 To lPoints - 1
Dim pElement As IElement
Set pElement = New MarkerElement
pElement.Geometry = GetRandomPoint(pFeat.Shape)
pGrpElement.AddElement pElement
Next l
pGC.AddElement pGrpElement, 0
pGCS.SelectElement pGrpElement
End If
Set pFeat = pEnumFeat.Next
Loop
pMxDoc.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
UngroupGraphics
CmdCreateShapefile
'ConvertGraphics2Shape
End Sub
Function GetRandomPoint(pPolyline As IPolyline) As IPoint
' get a random point along a line
Set GetRandomPoint = New Point
pPolyline.QueryPoint esriNoExtension, Rnd, True, GetRandomPoint
End Function
Sub UngroupGraphics()
Dim pUID As New UID
Dim pCmdItem As ICommandItem
' Use the GUID of the Ungroup command
pUID.Value = "{4B96A444-FA41-11D0-83AF-080009B996CC}"
' or you can use the ProgID
' pUID.Value = "esriCore.UngroupCommand"
pUID.SubType = 3
Set pCmdItem = Application.Document.CommandBars.Find(pUID)
pCmdItem.Execute
End Sub
Private Sub CmdCreateShapefile()
Dim theIMXDoc As IMxDocument
Set theIMXDoc = ThisDocument
Dim theimap As IMap
Set theimap = theIMXDoc.FocusMap
Dim theilayer As ILayer
Set theilayer = theIMXDoc.SelectedLayer
' Get the spatial reference
Dim pSR As ISpatialReference
Set pSR = theimap.SpatialReference
' Check to see if a map is selected or not.
If theIMXDoc.SelectedItem Is Nothing Then
MsgBox "Select a feature layer in the table of contents as the input feature class."
Exit Sub
End If
If Not TypeOf theIMXDoc.SelectedItem Is IFeatureLayer Then
MsgBox "No feature layer selected. Select a feature layer."
Exit Sub
End If
Dim theifeaturelayer As IFeatureLayer
Set theifeaturelayer = theilayer
'get the layer name
Dim theilayername As String
theilayername = theilayer.name
Dim theigeometry As IGeometry
Call makeshapefile(Nothing, theilayername, pSR)
End Sub
Public Sub makeshapefile(thePolyGeometry As IGeometry, theilayername, theSpatialRef As ISpatialReference)
On Error GoTo EH
Dim tFileName As String, tFilePath As String, tPath As String
Dim pGxObject As IGxObject
Dim pGxDialog As IGxDialog
Dim pGxFilter As IGxObjectFilter
Set pGxDialog = New GxDialog
Set pGxFilter = New GxFilterShapefiles
Set pGxDialog.ObjectFilter = pGxFilter
pGxDialog.AllowMultiSelect = False
pGxDialog.ButtonCaption = "Click to Save Point Shapefile"
pGxDialog.Title = "Enter name for random points"
pGxDialog.name = "rand_" & theilayername
If pGxDialog.DoModalSave(0) Then
Set pGxObject = pGxDialog.FinalLocation
Else
Exit Sub 'user cancelled operation
End If
If pGxDialog.ReplacingObject Then
MsgBox "Create a new filename", , "Random Points"
Exit Sub
End If
'
''------- GET FILE NAME AND OUTPUT FILE --------
tFileName = pGxDialog.name
tFilePath = pGxObject.FullName
Dim strfolder As String
Dim strname As String ' Dont include .shp extension
Const strShapeFieldName As String = "Shape"
strfolder = tFilePath