| |
Private Sub ConvertIndexPolygonGraphicToShape()
' adds all the selected Polygon Elements to the current edit layer
Dim pFeatureLayer As IFeatureLayer
Dim pMxDocument As IMxDocument
Set pMxDocument = ThisDocument
Set pFeatureLayer = pMxDocument.FocusMap.Layer(0)
StartEditingMapExtentPolygon
Dim pElementCollection As IElementCollection
Set pElementCollection = GetElements(pMxDocument.FocusMap)
If pElementCollection.Count > 0 Then
pEditor.StartOperation
Dim pEditLayers As IEditLayers
Set pEditLayers = pEditor
WriteElements pEditLayers.CurrentLayer.FeatureClass, pElementCollection
pEditor.StopOperation "AddGraphics2FeatClass"
DeleteElements pMxDocument.FocusMap, pElementCollection
End If
' Stop the Editing session
'StopEditingMapExtentPolygon
End Sub
Function GetElements(pGraphicsContainerSelect As IGraphicsContainerSelect) As IElementCollection
Set GetElements = New ElementCollection
Dim l As Long
For l = 0 To pGraphicsContainerSelect.ElementSelectionCount - 1
If TypeOf pGraphicsContainerSelect.SelectedElement(l) Is IPolygonElement Then
GetElements.Add pGraphicsContainerSelect.SelectedElement(l)
End If
Next l
End Function
Sub DeleteElements(pGraphicsContainer As IGraphicsContainer, pElementCollection As IElementCollection)
Dim pActiveView As IActiveView
Set pActiveView = pGraphicsContainer
' for refresh envelope
Dim d As Double
d = pActiveView.ScreenDisplay.DisplayTransformation.FittedBounds.Width / 20#
Dim l As Long
Dim pElement As IElement
Dim pEnvelope As IEnvelope
For l = 0 To pElementCollection.Count - 1
pElementCollection.QueryItem l, pElement
pGraphicsContainer.DeleteElement pElement
Set pEnvelope = pElement.Geometry.Envelope
pEnvelope.Expand d, d, False
pActiveView.PartialRefresh esriViewGraphics + esriViewGeography, Nothing, pEnvelope
Next l
End Sub
Sub WriteElements(pFeatureClass As IFeatureClass, pElementCollection As IElementCollection)
Dim pFeatureCursor As IFeatureCursor
Set pFeatureCursor = pFeatureClass.Insert(True)
Dim pFeatureBuffer As IFeatureBuffer
Set pFeatureBuffer = pFeatureClass.CreateFeatureBuffer
Dim l As Long
Dim pElement As IElement
If pFeatureClass.ShapeType = esriGeometryPolygon Then
For l = 0 To pElementCollection.Count - 1
pElementCollection.QueryItem l, pElement
Set pFeatureBuffer.Shape = pElement.Geometry
pFeatureCursor.InsertFeature pFeatureBuffer
Next l
pFeatureCursor.Flush
End If
End Sub |