Select to view content in your preferred language

VBA Script to add data to attribute table afte drawing a line

511
1
06-17-2010 01:27 AM
NicholasGeorge
New Contributor
Hello

I am looking for a VBA script that I can use so that I can draw a line as part of a shapefile file and then have a wondow with predefined fields pop up so the user can enter data into an attribute table. 

For example.  I draw a line representing roads.  Once I have drawn in the box would pop up asking for the road name, road number and towns.  These would be fields that already exist in the attibute table. The data entered in the window would, once OK was pressed be entered into the row associated with that line drawn. 

Any parts of this you have would be useful.  even just the calling of a box once a line has been drawn.  This is similar to the NOAA habitat digitiser tool that calls a box once a polygon has been drawn.
0 Kudos
1 Reply
JamesCrandall
MVP Alum
Hello

I am looking for a VBA script that I can use so that I can draw a line as part of a shapefile file and then have a wondow with predefined fields pop up so the user can enter data into an attribute table. 

For example.  I draw a line representing roads.  Once I have drawn in the box would pop up asking for the road name, road number and towns.  These would be fields that already exist in the attibute table. The data entered in the window would, once OK was pressed be entered into the row associated with that line drawn. 

Any parts of this you have would be useful.  even just the calling of a box once a line has been drawn.  This is similar to the NOAA habitat digitiser tool that calls a box once a polygon has been drawn.



In the most basic/generic sense, you would first, create a UserForm with controls to allow for data entry.  These controls could be whatever best represents the fields in the table/attributes, such as textbox controls.  Then I'd set an EditEvents and utililze the OnSketchFinished event to launch the UserForm and allow the user to enter the data into the controls.

Look into the IEditor Inteface for more info.

Ex:

Private pEditor As ESRI.ArcGIS.Editor.IEditor
Private WithEvents m_pEditEvents As ESRI.ArcGIS.Editor.Editor


Private Sub m_pEditEvents_OnSketchFinished() Handles m_pEditEvents.OnSketchFinished
        Try

            Dim pDoc As IMxDocument
            pDoc = m_pApp.Document
            Dim pActiveView As IActiveView = pDoc.ActiveView

            'If an edit session has not already been started, exit
            If pEditor.EditState = ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing Then 
                Exit Sub
            Else
               'do something
   
               'stop editing
              pEditor.StopEditing((True))

             End If

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