Hi Brain, try with a selection set and, then, a cursor. Mar
Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.Geodatabase Imports ESRI.ArcGIS.ArcMapUI Imports ESRI.ArcGIS.ADF Imports My Public Class MyClass ' Your real class name will appear here Inherits ESRI.ArcGIS.Desktop.AddIns.Button Public Sub New() End Sub Protected Overrides Sub OnClick() Dim pMxDoc As IMxDocument pMxDoc = CType(ArcMap.Application.Document, IMxDocument) Dim pMap As IMap pMap = pMxDoc.FocusMap Dim pEnumLayer As IEnumLayer pEnumLayer = pMap.Layers pEnumLayer.Reset() Dim pLayer As ILayer pLayer = pEnumLayer.Next Dim pFLayer As IFeatureLayer Do While Not pLayer Is Nothing If pLayer.Name = "MY_LAYER_NAME" And TypeOf pLayer Is IFeatureLayer Then ' Substitute your real layer name pFLayer = TryCast(pLayer, IFeatureLayer) Exit Do End If pLayer = pEnumLayer.Next Loop If pFLayer is Nothing Then MsgBox("No Layer Found") Exit Sub End If Dim pFSel As IFeatureSelection pFSel = pFLayer Dim pSelSet As ESRI.ArcGIS.Geodatabase.ISelectionSet2 pSelSet = pFSel.SelectionSet If pSelSet.Count < 1 Then MsgBox("No Features Selected") Return End If Using comReleaser As ComReleaser = New ComReleaser() ' Recommended for cleaning up cursors Dim pFCursor As ESRI.ArcGIS.Geodatabase.IFeatureCursor = Nothing pSelSet.Search(Nothing, False, pFCursor) comReleaser.ManageLifetime(pFCursor) Dim pFeature As IFeature pFeature = pFCursor.NextFeature ' Get First Feature If pFeature Is Nothing Then MsgBox("No Features Selected!") ' Just in case, but probably already taken care of earlier Return End If Dim lFIndex As Long lFIndex = pFCursor.FindField("MY_FIELD_NAME") ' Replace with your field name If lFIndex > -1 Then Dim fValue as String ' Substute the correct data type to match the field type Do While Not pFeature Is Nothing fValue = pFeature.Value(lFIndex) ' Do something with the value stored in fValue pFeature = pFCursor.NextFeature Loop End If End Using End Sub Protected Overrides Sub OnUpdate() End Sub End Class
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.