+ Reply to Thread
Results 1 to 3 of 3

Thread: ArcMap 9.2 VS2005 starting conversion from VBA to dotnet

  1. #1
    John Barnes
    Join Date
    Jun 2010
    Posts
    46
    Points
    3
    Answers Provided
    0


    0

    Default ArcMap 9.2 VS2005 starting conversion from VBA to dotnet

    Can anyone give me a good code example for a tool that will allow the user to select a feature and return the attribute information?

    Searching I notice there are big changes between versions 9.1, 9.2 and 10. I am using VS2005 and 9.2 so please specific to these versions would be great.

    Thanks,

    John Barnes

  2. #2
    Duncan Hornby
    Join Date
    Apr 2010
    Posts
    930
    Points
    310
    Answers Provided
    52


    0

    Lightbulb Re: ArcMap 9.2 VS2005 starting conversion from VBA to dotnet

    John,

    Do you know about the EDN sites? These have a code sample section which you can filter for 9.2 and trawl to find examples. I think these sites have been "archived" by ESRI as they are for older versions of their software. Thankfully they have not removed them as there are a great number of people who still use older versions of their software, I for one am still actively using 9.1!

    The EDN site can be found here

    Duncan
    If you feel my response answered your question please vote it up, I want to be famous!

  3. #3
    John Barnes
    Join Date
    Jun 2010
    Posts
    46
    Points
    3
    Answers Provided
    0


    0

    Default Re: ArcMap 9.2 VS2005 starting conversion from VBA to dotnet

    Evidently no could help me so I figured it out on my own.

    Not actually that much different than VBA.

    Public Overrides Sub OnMouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)
    'TODO: Add RetrunAttributes.OnClick implementation
    'TODO: Add RetrunAttributes.OnMouseUp implementation

    'Get project vital data
    Dim pMxDoc As IMxDocument
    Dim myApp As IMxApplication
    myApp = m_application
    pMxDoc = CType(m_application.Document, IMxDocument)

    'Get the map and layer information
    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 = "tlots" And TypeOf pLayer Is IFeatureLayer Then ' Substitute your real layer name
    pFLayer = TryCast(pLayer, IFeatureLayer)
    Exit Do
    End If
    pLayer = pEnumLayer.Next
    Loop


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Get the users' clicked point
    'Create an envelope at the point
    'Select the feature at the clicked location with the envelope
    Dim clickedPoint As IPoint = pMxDoc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y)
    Dim pEnvelope As Envelope = clickedPoint.Envelope
    Dim pView As IActiveView = pMap
    pEnvelope.Expand(pMxDoc.SearchTolerance, pMxDoc.SearchTolerance, False)
    pMap.SelectByShape(pEnvelope, myApp.SelectionEnvironment, False)
    pView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Check to make sure the layer is available
    If pFLayer Is Nothing Then
    MsgBox("No Layer Found")
    Exit Sub
    End If

    'Check to make sure a feature is selected
    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

    'Return the appropriate attribute from the selected feature
    Dim lFIndex As Long
    lFIndex = pFCursor.FindField("Acad_Text") ' Replace with your field name
    If lFIndex > -1 Then
    Do While Not pFeature Is Nothing
    fValue = pFeature.Value(lFIndex) 'I declare the fValue above the region
    pFeature = pFCursor.NextFeature
    Loop
    End If

    'Display the selected attribute
    MsgBox(fValue)

    End Using

    End Sub

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts