Select to view content in your preferred language

simulate a double click to turn on Sketch Edit mode

1834
24
05-18-2010 06:23 AM
DanNguyen
Emerging Contributor
Does anyone know how to simulate a double click in VB to turn on Sketch Edit mode programmatically?

Thanks in advance for your help.
0 Kudos
24 Replies
JamesCrandall
MVP Frequent Contributor
Does anyone know how to simulate a double click in VB to turn on Sketch Edit mode programmatically?

Thanks in advance for your help.


Not real sure where you'd get the double-click event at, but in order to invoke the Edit Sketch you will have to start an edit session and specify the target layer you want to create/modify...

VB.NET:

'This ex shows a button on a ToolBar I've created
Private Sub btnDrawTarget_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDrawTarget.Click
           Dim pEditTask As ESRI.ArcGIS.Editor.IEditTask
            GetEditorReference()
            startEditing(pEditor)
            If m_flag2 = True Then
                SetEvents()
                pEditTask = GetEditTaskByName(pEditor, "Create New Feature")
                pEditor.CurrentTask = pEditTask
            End If
End Sub

Private Sub GetEditorReference()
        Dim pID As ESRI.ArcGIS.esriSystem.UID
        pID = New ESRI.ArcGIS.esriSystem.UID
        pID.Value = "esriCore.Editor"

        pEditor = m_pApp.FindExtensionByCLSID(pID)
 End Sub

Private Sub SetEvents()
        'set the current tool to be the editor Sketch tool
        Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem
        Dim pUID As New ESRI.ArcGIS.esriSystem.UID

        pUID.value = "esriCore.SketchTool"

        pCommandItem = m_pApp.Document.CommandBars.Find(pUID)
        m_pApp.CurrentTool = pCommandItem
        m_pEditEvents = pEditor
End Sub

Private Sub startEditing(ByRef pEditor As ESRI.ArcGIS.Editor.IEditor)

        Try

            Dim pMxDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument
            Dim pMap As ESRI.ArcGIS.Carto.IMap
            Dim pfeaturelayer As ESRI.ArcGIS.Carto.IFeatureLayer
            Dim pDataset As ESRI.ArcGIS.Geodatabase.IDataset
            Dim pEditLayers As ESRI.ArcGIS.Editor.IEditLayers
            Dim msg As Object

            pMxDoc = m_pApp.Document
            pMap = pMxDoc.FocusMap
            pEditLayers = pEditor
 
'Check to see if proper dataset is loaded before editing, if so, then edit
            Dim i, idx As Integer
            Dim pGeoFeatureLayer As ESRI.ArcGIS.Carto.IGeoFeatureLayer
            m_flag2 = False
            For i = 0 To pMxDoc.FocusMap.LayerCount - 1
                If (TypeOf pMxDoc.FocusMap.Layer(i) Is ESRI.ArcGIS.Carto.IGeoFeatureLayer) Then
                    pGeoFeatureLayer = pMxDoc.FocusMap.Layer(i)
                    If pGeoFeatureLayer.Name = "The Name of The Layer you Want to Edit Goes Here" Then
                        m_flag2 = True
                        idx = i
                        Exit For
                    End If
                End If
            Next i

            If m_flag2 = True Then
                pfeaturelayer = pMap.Layer(idx)
                pDataset = pfeaturelayer.FeatureClass

                pEditor.StartEditing(pDataset.Workspace)
                pEditor.StartOperation()
                pEditLayers.SetCurrentLayer(pfeaturelayer, 0)
            End If

        Catch ex As Exception
            MsgBox(ex.ToString)
            Exit Sub
        End Try

    End Sub
0 Kudos
DanNguyen
Emerging Contributor
Hi James,

Thanks for replying.
I got the code to turn on the Editor and select the line segment I want but Edit Sketch doesn't know its geometry.  For Edit Sketch to know about its geometry I have to double clik on the line segment manually and I want to program the double click because I have a list of line segments that I want to go through and edit.

Thanks!
0 Kudos
JamesCrandall
MVP Frequent Contributor
dan,

What programming environment are you working in?  VBA, VB6, VB.NET?
0 Kudos
DanNguyen
Emerging Contributor
James,

It is VBA.

Dan.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Hi James,

Thanks for replying.
I got the code to turn on the Editor and select the line segment I want but Edit Sketch doesn't know its geometry.  For Edit Sketch to know about its geometry I have to double clik on the line segment manually and I want to program the double click because I have a list of line segments that I want to go through and edit.

Thanks!


Hmm.. I'm not exactly sure what you are trying to accomplish.  Also, you are not going to be able to alter how the existing built in tools of ArcMap actually behave because it's compiled.  Your best bet might be in setting up an Event listener to a double-click event that occurs in the ActiveView maybe?

Not sure --- my VBA is all tucked away and rarely do I even access it because the .mxd's take so long to open (because they have layers from old SDE db's! 😄 )

Sorry I couldn't be of more help.
0 Kudos
DanNguyen
Emerging Contributor
Hi James,

That is OK if you can't help anymore.

Just so you know ... I have a layer of polylines and for each of these polyline, I want to insert a vertex on it (besides its existing vertices) at a known X,Y coordinates.  I got most everything figured out except how to turn on its Edit Sketch Properties.  Manually, when you double click on a polyline you would see all its vertices.  And I want to do this via the codes.

I know VB 6, VB.Net and C also.  So if you have the codes in these languages, that will work too.

Thanks, James.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Hi James,

That is OK if you can't help anymore.

Just so you know ... I have a layer of polylines and for each of these polyline, I want to insert a vertex on it (besides its existing vertices) at a known X,Y coordinates.  I got most everything figured out except how to turn on its Edit Sketch Properties.  Manually, when you double click on a polyline you would see all its vertices.  And I want to do this via the codes.

I know VB 6, VB.Net and C also.  So if you have the codes in these languages, that will work too.

Thanks, James.


But Dan, the code I posted above will do that.  It starts an edit session, sets the target layer, and waits for the user to add features.
0 Kudos
DanNguyen
Emerging Contributor
James,
what do you mean by "and wait for user to add feature"? (BTW, I'm rather new to ArcGIS programming)

I forgot to mention that the X,Y coordinates are in a point layer and they are related to the polyines by OBJECT_ID.

I want the codes to go through the polyline layer and for each polyline, insert a vertex at its corresponding X,Y in the point layer.

Does your codes wait for user interactions?

Thanks,

Dan.
0 Kudos
JamesCrandall
MVP Frequent Contributor

I want the codes to go through the polyline layer and for each polyline, insert a vertex at its corresponding X,Y in the point layer.



Now we are getting pretty far away from what you orignially posted what you wanted --- I thought you wanted to invoke an edit session and allow the user to add features via "Create New Features".  That's what the code I posted does.

...Now it seems that you'd like to generate verticies at the intersection points of the polyline layer, which is pretty different than what I thought you needed per your first post.

I don't have any examples of what you want and would have to hunt around for something.  Do a search for creating verticies at intersections.
0 Kudos