Select Features Tool - VB.NET

3678
4
06-15-2010 12:33 PM
RuchiraWelikala
Occasional Contributor
Hi All,
The code belows is the OnClick procedure for one of the custom tools I'm making.  The problem is, when the initial tool is activated, I want it to check if the appropriate features are selected.  If it isn't selected, I want the Select Features tool in ArcMap to activate so the user can select the specific feature. 
I get an error "m_application.CurrentTool = pCommand".
If anyone has an advice for me, that'd be greatly appreciated.

Thanks

    Public Overrides Sub OnClick()
        Try
           
            'TODO: Add ClipTool.OnClick implementation
            Dim pMap As IMxDocument = GetMxDocumentFromArcMap(m_application)
            Dim pFeatLayer As IFeatureLayer = pMap.SelectedLayer
            Dim pFeatSelection As IFeatureSelection = pFeatLayer
            Dim pSelSet As ISelectionSet
            pSelSet = pFeatSelection.SelectionSet

            If pSelSet.Count = 0 Then
                MsgBox("Please make a selection")

                Dim pCommand As ICommand
                pCommand = New ControlsSelectFeaturesToolClass ' The selectfeatures tool
                pCommand.OnCreate(m_application)
                If pCommand.Enabled = True Then
                    m_application.CurrentTool = pCommand
                End If
                Exit Sub
            End If
            Call CreateWindow(GetMxDocumentFromArcMap(m_application))

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
0 Kudos
4 Replies
RuchiraWelikala
Occasional Contributor
Nada?  Any help would be appreciated!
0 Kudos
JamesCrandall
MVP Frequent Contributor
Does this line really work as expected?

pCommand = New ControlsSelectFeaturesToolClass ' The selectfeatures tool

From what I see, you need to invoke the correct UID for that SelectFeaturesTool.  Not sure what dev environment you are working in, but here's how I start the SelecteFeatures Tool in the Button Click event in a .NET app:

Private Sub btnRunByPolyGraphic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRunByPolyGraphic.Click

Dim pUID As New UID
pUID.Value = "esriArcMapUI.SelectFeaturesTool"
m_pApp.CurrentTool = m_pApp.Document.CommandBars.Find(pUID)

'do something

End Sub


Also, are you sure you want to set the .CurrentTool = pCommand IF pCommand is already .Enabled?  Cause that is what you are doing in the code:

If pCommand.Enabled = True Then
  m_application.CurrentTool = pCommand
 End If
Exit Sub


I mean, if it's already enabled then you don't need to set the current tool to it, right?  I don't know, maybe I'm just a bit confused on what you are attempting there.
0 Kudos
AlexanderGray
Occasional Contributor III
CurrentTool takes a ICommandItem not an ICommand.  The ICommandItem has a reference to the command.  I have never tried to create and OnCreate the commands myself, I don't think that is going to work.  You need to let ArcMap create the command.  James' way is how you get the command.  I usually Initialize a variable and setting it to the currenttool in a seperate line, if something goes wrong it helps me know if the problem was finding the commanditem or setting it to the currenttool.

Dim pUID As New UIDClass
pUID.Value = "esriArcMapUI.SelectFeaturesTool"
Dim selectFeatureCmdItm = m_pApp.Document.CommandBars.Find(pUID)
m_pApp.CurrentTool = selectFeatureCmdItm
0 Kudos
RuchiraWelikala
Occasional Contributor
Thanks for the help guys.
The method I tried worked for a standalone application I used before.  I set a windows form button's click event to be the selection tool.  Worked fine.
Guess it's not the same with ArcMap. 

Thanks again guys!
0 Kudos