<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Inserting LR Event Features with VBA in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/inserting-lr-event-features-with-vba/m-p/274962#M7034</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have searched the old and new forums and not seen any code that inserts new records into a Linear Reference Event Feature Layer using VBA.&amp;nbsp; After some experimenting I found it was not possible to insert the features directly into the LR Event Layer, but it was possible to insert them into the underlying event table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code below is what I came up with.&amp;nbsp; It duplicates selected LR Event Features by inserting copies into the underlying Event table (I use it to split LR line features when changes in my sidewalk network occur).&amp;nbsp; The code also reselects the original and new duplicated features so that they will display in the LR Event Feature Layer's Tableview.&amp;nbsp; I hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Sub AddLRRecord()
&amp;nbsp; ' Get a reference to the Event Layer through the map.
&amp;nbsp; Dim pMxDoc As IMxDocument
&amp;nbsp; Set pMxDoc = ThisDocument
&amp;nbsp; Dim pMap As IMap
&amp;nbsp; Set pMap = pMxDoc.FocusMap
&amp;nbsp; Dim pLayer As ILayer
&amp;nbsp; Dim i As Long
&amp;nbsp; For i = 0 To pMap.LayerCount - 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pLayer = pMap.Layer(i)
&amp;nbsp;&amp;nbsp;&amp;nbsp; If pLayer.Name = "SIDEWALKS Events" Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit For
&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp; Next i
&amp;nbsp; If pLayer Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Layer Not Found"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; Dim pFLayer As IFeatureLayer
&amp;nbsp; Set pFLayer = pLayer

&amp;nbsp; ' Get the LR Event layer's Selection Set.
&amp;nbsp; Dim pFSel As IFeatureSelection
&amp;nbsp; Set pFSel = pFLayer
&amp;nbsp; Dim pSelSet As ISelectionSet
&amp;nbsp; Set pSelSet = pFSel.SelectionSet

&amp;nbsp; ' Create a where clause to select records from underlying event table using OID values.
&amp;nbsp; Dim pEnumIDs As IEnumIDs
&amp;nbsp; Set pEnumIDs = pSelSet.IDs
&amp;nbsp; Dim strWhere As String
&amp;nbsp; strWhere = """OBJECTID"" IN ("
&amp;nbsp; Dim lID As Long
&amp;nbsp; pEnumIDs.Reset
&amp;nbsp; lID = pEnumIDs.Next
&amp;nbsp; Do While lID &amp;lt;&amp;gt; -1
&amp;nbsp;&amp;nbsp;&amp;nbsp; strWhere = strWhere &amp;amp; lID &amp;amp; ","
&amp;nbsp;&amp;nbsp;&amp;nbsp; lID = pEnumIDs.Next
&amp;nbsp; Loop
&amp;nbsp; strWhere = Left(strWhere, Len(strWhere) - 1) &amp;amp; ")"
&amp;nbsp; If strWhere = """OBJECTID"" IN )" Then ' Make sure something was selected
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "No Sidewalks selected"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If

&amp;nbsp; ' Select the records in the underlying event table.
&amp;nbsp; Dim pQF As IQueryFilter
&amp;nbsp; Set pQF = New QueryFilter
&amp;nbsp; pQF.WhereClause = strWhere
&amp;nbsp; Dim pRouteEventSource As IRouteEventSource ' This is the interface for getting the Event Table
&amp;nbsp; Set pRouteEventSource = pFLayer.FeatureClass
&amp;nbsp; Dim pTable As ITable
&amp;nbsp; Set pTable = pRouteEventSource.EventTable
&amp;nbsp; Dim pCursor As ICursor
&amp;nbsp; Set pCursor = pTable.Search(pQF, False)

&amp;nbsp; ' Copy the records and prepare a new where clause to select original and new features in the LR Event layer.
&amp;nbsp; Dim pICursor As ICursor ' Set up insert cursor for underlying event table.
&amp;nbsp; Set pICursor = pTable.Insert(True)
&amp;nbsp; Dim pRowB As IRowBuffer
&amp;nbsp; Set pRowB = pCursor.NextRow
&amp;nbsp; Dim lFIDC As Long
&amp;nbsp; lFIDC = pRowB.Fields.FindField("FID_CENTERLINE")
&amp;nbsp; Dim lRoadSide As Long
&amp;nbsp; lRoadSide = pRowB.Fields.FindField("ROAD_SIDE")
&amp;nbsp; strWhere = """FID_CENTERLINE"" IN (" ' Create a new query for selecting in LR Event layer.
&amp;nbsp; Dim strWhere2 As String
&amp;nbsp; strWhere2 = " AND ""ROAD_SIDE"" IN ("
&amp;nbsp; Do While Not pRowB Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; pICursor.InsertRow pRowB ' This duplicates the record in the event table.
&amp;nbsp;&amp;nbsp;&amp;nbsp; strWhere = strWhere &amp;amp; pRowB.Value(lFIDC) &amp;amp; "," ' Adding records to where clause.
&amp;nbsp;&amp;nbsp;&amp;nbsp; strWhere2 = strWhere2 &amp;amp; "'" &amp;amp; pRowB.Value(lRoadSide) &amp;amp; "',"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRowB = pCursor.NextRow
&amp;nbsp; Loop
&amp;nbsp; strWhere = Left(strWhere, Len(strWhere) - 1) &amp;amp; ")"
&amp;nbsp; strWhere2 = Left(strWhere2, Len(strWhere2) - 1) &amp;amp; ")"
&amp;nbsp; strWhere = strWhere &amp;amp; strWhere2

&amp;nbsp; ' Reselect original records and duplicated records in the event layer.
&amp;nbsp; pQF.WhereClause = strWhere
&amp;nbsp; pFSel.SelectFeatures pQF, esriSelectionResultNew, False
&amp;nbsp; Set pSelSet = pFSel.SelectionSet ' A SelectionSet will show selection in user tableview.
End Sub
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 01 Oct 2010 19:24:03 GMT</pubDate>
    <dc:creator>RichardFairhurst</dc:creator>
    <dc:date>2010-10-01T19:24:03Z</dc:date>
    <item>
      <title>Inserting LR Event Features with VBA</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/inserting-lr-event-features-with-vba/m-p/274962#M7034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have searched the old and new forums and not seen any code that inserts new records into a Linear Reference Event Feature Layer using VBA.&amp;nbsp; After some experimenting I found it was not possible to insert the features directly into the LR Event Layer, but it was possible to insert them into the underlying event table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code below is what I came up with.&amp;nbsp; It duplicates selected LR Event Features by inserting copies into the underlying Event table (I use it to split LR line features when changes in my sidewalk network occur).&amp;nbsp; The code also reselects the original and new duplicated features so that they will display in the LR Event Feature Layer's Tableview.&amp;nbsp; I hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Sub AddLRRecord()
&amp;nbsp; ' Get a reference to the Event Layer through the map.
&amp;nbsp; Dim pMxDoc As IMxDocument
&amp;nbsp; Set pMxDoc = ThisDocument
&amp;nbsp; Dim pMap As IMap
&amp;nbsp; Set pMap = pMxDoc.FocusMap
&amp;nbsp; Dim pLayer As ILayer
&amp;nbsp; Dim i As Long
&amp;nbsp; For i = 0 To pMap.LayerCount - 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pLayer = pMap.Layer(i)
&amp;nbsp;&amp;nbsp;&amp;nbsp; If pLayer.Name = "SIDEWALKS Events" Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit For
&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp; Next i
&amp;nbsp; If pLayer Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Layer Not Found"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; Dim pFLayer As IFeatureLayer
&amp;nbsp; Set pFLayer = pLayer

&amp;nbsp; ' Get the LR Event layer's Selection Set.
&amp;nbsp; Dim pFSel As IFeatureSelection
&amp;nbsp; Set pFSel = pFLayer
&amp;nbsp; Dim pSelSet As ISelectionSet
&amp;nbsp; Set pSelSet = pFSel.SelectionSet

&amp;nbsp; ' Create a where clause to select records from underlying event table using OID values.
&amp;nbsp; Dim pEnumIDs As IEnumIDs
&amp;nbsp; Set pEnumIDs = pSelSet.IDs
&amp;nbsp; Dim strWhere As String
&amp;nbsp; strWhere = """OBJECTID"" IN ("
&amp;nbsp; Dim lID As Long
&amp;nbsp; pEnumIDs.Reset
&amp;nbsp; lID = pEnumIDs.Next
&amp;nbsp; Do While lID &amp;lt;&amp;gt; -1
&amp;nbsp;&amp;nbsp;&amp;nbsp; strWhere = strWhere &amp;amp; lID &amp;amp; ","
&amp;nbsp;&amp;nbsp;&amp;nbsp; lID = pEnumIDs.Next
&amp;nbsp; Loop
&amp;nbsp; strWhere = Left(strWhere, Len(strWhere) - 1) &amp;amp; ")"
&amp;nbsp; If strWhere = """OBJECTID"" IN )" Then ' Make sure something was selected
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "No Sidewalks selected"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If

&amp;nbsp; ' Select the records in the underlying event table.
&amp;nbsp; Dim pQF As IQueryFilter
&amp;nbsp; Set pQF = New QueryFilter
&amp;nbsp; pQF.WhereClause = strWhere
&amp;nbsp; Dim pRouteEventSource As IRouteEventSource ' This is the interface for getting the Event Table
&amp;nbsp; Set pRouteEventSource = pFLayer.FeatureClass
&amp;nbsp; Dim pTable As ITable
&amp;nbsp; Set pTable = pRouteEventSource.EventTable
&amp;nbsp; Dim pCursor As ICursor
&amp;nbsp; Set pCursor = pTable.Search(pQF, False)

&amp;nbsp; ' Copy the records and prepare a new where clause to select original and new features in the LR Event layer.
&amp;nbsp; Dim pICursor As ICursor ' Set up insert cursor for underlying event table.
&amp;nbsp; Set pICursor = pTable.Insert(True)
&amp;nbsp; Dim pRowB As IRowBuffer
&amp;nbsp; Set pRowB = pCursor.NextRow
&amp;nbsp; Dim lFIDC As Long
&amp;nbsp; lFIDC = pRowB.Fields.FindField("FID_CENTERLINE")
&amp;nbsp; Dim lRoadSide As Long
&amp;nbsp; lRoadSide = pRowB.Fields.FindField("ROAD_SIDE")
&amp;nbsp; strWhere = """FID_CENTERLINE"" IN (" ' Create a new query for selecting in LR Event layer.
&amp;nbsp; Dim strWhere2 As String
&amp;nbsp; strWhere2 = " AND ""ROAD_SIDE"" IN ("
&amp;nbsp; Do While Not pRowB Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; pICursor.InsertRow pRowB ' This duplicates the record in the event table.
&amp;nbsp;&amp;nbsp;&amp;nbsp; strWhere = strWhere &amp;amp; pRowB.Value(lFIDC) &amp;amp; "," ' Adding records to where clause.
&amp;nbsp;&amp;nbsp;&amp;nbsp; strWhere2 = strWhere2 &amp;amp; "'" &amp;amp; pRowB.Value(lRoadSide) &amp;amp; "',"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRowB = pCursor.NextRow
&amp;nbsp; Loop
&amp;nbsp; strWhere = Left(strWhere, Len(strWhere) - 1) &amp;amp; ")"
&amp;nbsp; strWhere2 = Left(strWhere2, Len(strWhere2) - 1) &amp;amp; ")"
&amp;nbsp; strWhere = strWhere &amp;amp; strWhere2

&amp;nbsp; ' Reselect original records and duplicated records in the event layer.
&amp;nbsp; pQF.WhereClause = strWhere
&amp;nbsp; pFSel.SelectFeatures pQF, esriSelectionResultNew, False
&amp;nbsp; Set pSelSet = pFSel.SelectionSet ' A SelectionSet will show selection in user tableview.
End Sub
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Oct 2010 19:24:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/inserting-lr-event-features-with-vba/m-p/274962#M7034</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-10-01T19:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting LR Event Features with VBA</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/inserting-lr-event-features-with-vba/m-p/274963#M7035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have created a new version of the split code designed to work as a UIToolControl that can split a selected LR Line Event where a mouse was clicked.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
&amp;nbsp; Dim pEditor As IEditor
&amp;nbsp; Dim pID As New UID
&amp;nbsp; pID = "esriEditor.Editor"
&amp;nbsp; Set pEditor = Application.FindExtensionByCLSID(pID)

&amp;nbsp; If Not pEditor.EditState = esriStateEditing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Not in an Edit Session!.&amp;nbsp; Please start Editor."
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; 
&amp;nbsp; Dim pMxDoc As IMxDocument
&amp;nbsp; Set pMxDoc = Application.Document
&amp;nbsp; Dim pMap As IMap
&amp;nbsp; Set pMap = pMxDoc.FocusMap
&amp;nbsp; Dim i As Long
&amp;nbsp; Dim pLayer As ILayer
&amp;nbsp; For i = 0 To pMap.LayerCount - 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pLayer = pMap.Layer(i)
&amp;nbsp;&amp;nbsp;&amp;nbsp; If pLayer.Name = "SIDEWALKS Events" Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit For
&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp; Next i
&amp;nbsp; If pLayer Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Layer Not Found"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; Dim pFLayer As IFeatureLayer
&amp;nbsp; Set pFLayer = pLayer
&amp;nbsp; If pFLayer Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Layer is not a Feature Layer!"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; 
 
&amp;nbsp; If Not TypeOf pFLayer.FeatureClass Is IRouteEventSource Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Layer is not a Route Event Source!"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; Dim pRouteEventSource As IRouteEventSource
&amp;nbsp; Set pRouteEventSource = pFLayer.FeatureClass
&amp;nbsp; If Not TypeOf pRouteEventSource.EventProperties Is IRouteMeasureLineProperties Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Layer is not a Line Event Layer!"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; 
&amp;nbsp; Dim pDataset As IDataset
&amp;nbsp; Set pDataset = pRouteEventSource.EventTable
&amp;nbsp; Dim pProps As IPropertySet
&amp;nbsp; Set pProps = pEditor.EditWorkspace.ConnectionProperties
&amp;nbsp; If Not pDataset.Workspace.ConnectionProperties.IsEqual(pProps) Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Workspace of Sidewalk Events Layer is not being edited!"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If

&amp;nbsp; 'Get the point where the user clicked
&amp;nbsp; If pMxDoc.CurrentLocation.IsEmpty Then Exit Sub
&amp;nbsp; 'Clone the point because we don't want to alter
&amp;nbsp; 'the actual document's current location point
&amp;nbsp; Dim pClone As IClone
&amp;nbsp; Set pClone = pMxDoc.CurrentLocation
&amp;nbsp; Dim pPoint As IPoint
&amp;nbsp; Set pPoint = pClone.Clone
&amp;nbsp; 
&amp;nbsp; Dim pFSel As IFeatureSelection
&amp;nbsp; Set pFSel = pFLayer
&amp;nbsp; Dim pSelSet As ISelectionSet
&amp;nbsp; Set pSelSet = pFSel.SelectionSet
&amp;nbsp; If pSelSet.Count &amp;lt; 1 Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "No Sidewalks selected"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp; End If
&amp;nbsp; 
&amp;nbsp; ' Read selected records to create an update where clause using OID values
&amp;nbsp; Dim pCursor As ICursor
&amp;nbsp; Dim pRow As IRow
&amp;nbsp; pSelSet.Search Nothing, False, pCursor
&amp;nbsp; Set pRow = pCursor.NextRow
&amp;nbsp; Dim strWhere As String
&amp;nbsp; strWhere = """OBJECTID"" IN ("
&amp;nbsp; 
&amp;nbsp; ' This where clause is specific to my sidewalk data.
&amp;nbsp; Dim lFIDC As Long
&amp;nbsp; lFIDC = pRow.Fields.FindField("FID_CENTERLINE")
&amp;nbsp; Dim lRoadSide As Long
&amp;nbsp; lRoadSide = pRow.Fields.FindField("ROAD_SIDE")
&amp;nbsp; Dim strWhere2 As String
&amp;nbsp; Dim strwhere3 As String
&amp;nbsp; strWhere2 = """FID_CENTERLINE"" IN ("
&amp;nbsp; strwhere3 = " AND ""ROAD_SIDE"" IN ("
&amp;nbsp; 
&amp;nbsp; ' Loop through selected records to create two where clauses.
&amp;nbsp; Do While Not pRow Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' This clause is common to all GDBs
&amp;nbsp;&amp;nbsp;&amp;nbsp; strWhere = strWhere &amp;amp; pRow.OID &amp;amp; ","
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; strWhere2 = strWhere2 &amp;amp; pRow.Value(lFIDC) &amp;amp; ","
&amp;nbsp;&amp;nbsp;&amp;nbsp; strwhere3 = strwhere3 &amp;amp; "'" &amp;amp; pRow.Value(lRoadSide) &amp;amp; "',"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRow = pCursor.NextRow
&amp;nbsp; Loop
&amp;nbsp; ' Complete where clause common to all GDBs.
&amp;nbsp; strWhere = Left(strWhere, Len(strWhere) - 1) &amp;amp; ")"

&amp;nbsp; strWhere2 = Left(strWhere2, Len(strWhere2) - 1) &amp;amp; ")"
&amp;nbsp; strwhere3 = Left(strwhere3, Len(strwhere3) - 1) &amp;amp; ")"
&amp;nbsp; strWhere2 = strWhere2 &amp;amp; strwhere3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; Dim pQF As IQueryFilter
&amp;nbsp; Set pQF = New QueryFilter
&amp;nbsp; 
&amp;nbsp; ' Do the Split in an edit operations so that it can be undone
&amp;nbsp; pEditor.StartOperation
&amp;nbsp;&amp;nbsp;&amp;nbsp; SplitLRRecord pPoint, pRouteEventSource, strWhere

&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Reselect original records and added records for split in the event layer.
&amp;nbsp;&amp;nbsp;&amp;nbsp; pQF.WhereClause = strWhere2
&amp;nbsp;&amp;nbsp;&amp;nbsp; pFSel.SelectFeatures pQF, esriSelectionResultNew, False
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSelSet = pFSel.SelectionSet
&amp;nbsp; pEditor.StopOperation "Split Event Record"
&amp;nbsp; 
&amp;nbsp; ' Switch tool to Select Feature tools to avoid accidental split and allow new selection
&amp;nbsp; Dim pItem As ICommandItem
&amp;nbsp; Set pItem = CommandBars.Find(arcid.Query_SelectFeatures)
&amp;nbsp; Set Application.CurrentTool = pItem
End Sub

Sub SplitLRRecord(ByVal pPoint As IPoint, ByVal pRouteEventSource As IRouteEventSource, ByVal strWhere As String)
&amp;nbsp; ' Select the records in the underlying event table.
&amp;nbsp; Dim pQF As IQueryFilter
&amp;nbsp; Set pQF = New QueryFilter
&amp;nbsp; pQF.WhereClause = strWhere
&amp;nbsp; Dim pTable As ITable
&amp;nbsp; Set pTable = pRouteEventSource.EventTable
&amp;nbsp; Dim pICursor As ICursor
&amp;nbsp; Set pICursor = pTable.Insert(True)
&amp;nbsp; Dim pRowB As IRowBuffer
&amp;nbsp; Set pRowB = pTable.CreateRowBuffer
&amp;nbsp; Dim pCursor As ICursor
&amp;nbsp; Set pCursor = pTable.Update(pQF, False)
&amp;nbsp; 
&amp;nbsp; ' Get the event fields for selecting Routes
&amp;nbsp; Dim pEventRouteField As String
&amp;nbsp; pEventRouteField = pRouteEventSource.EventProperties.EventRouteIDFieldName
&amp;nbsp; Dim pEventRouteIndex As Long
&amp;nbsp; pEventRouteIndex = pTable.FindField(pEventRouteField)
&amp;nbsp; ' Get Route Feature Class and fields
&amp;nbsp; Dim pRouteFC As IFeatureClass
&amp;nbsp; Set pRouteFC = pRouteEventSource.RouteLocator.RouteFeatureClass
&amp;nbsp; Dim pRouteField As String
&amp;nbsp; pRouteField = pRouteEventSource.RouteLocator.RouteIDFieldName
&amp;nbsp; 'Create QueryFilter and Feature Cursor for querying routes
&amp;nbsp; Dim pQFRoute As IQueryFilter
&amp;nbsp; Set pQFRoute = New QueryFilter
&amp;nbsp; Dim pFCursor As IFeatureCursor
&amp;nbsp; Dim pFeature As IFeature
&amp;nbsp; ' Variables for NearestMToPoint Sub
&amp;nbsp; Dim pCurve As ICurve
&amp;nbsp; Dim dMeas As Double
&amp;nbsp; Dim pNearPoint As IPoint
&amp;nbsp; Dim dNearDist As Double
&amp;nbsp; Dim bRight As Boolean
&amp;nbsp; Dim dFromMeas As Double
&amp;nbsp; Dim dToMeas As Double
&amp;nbsp; 
&amp;nbsp; ' Find records that the point splits and modify measures of existing and inserted event.
&amp;nbsp; Dim pRow As IRow ' Normal row for modifying original row measure
&amp;nbsp; Set pRow = pCursor.NextRow
&amp;nbsp; Dim lFromMeas As Long
&amp;nbsp; Dim lToMeas As Long
&amp;nbsp; Dim pRMLP As IRouteMeasureLineProperties
&amp;nbsp; Set pRMLP = pRouteEventSource.EventProperties
&amp;nbsp; lFromMeas = pRow.Fields.FindField(pRMLP.FromMeasureFieldName)
&amp;nbsp; lToMeas = pRow.Fields.FindField(pRMLP.ToMeasureFieldName)
&amp;nbsp; Do While Not pRow Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; pQFRoute.WhereClause = """" &amp;amp; pRouteField &amp;amp; """ = '" &amp;amp; pRow.Value(pEventRouteIndex) &amp;amp; "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFCursor = pRouteFC.Search(pQFRoute, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeature = pFCursor.NextFeature
&amp;nbsp;&amp;nbsp;&amp;nbsp; If Not pFeature Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pCurve = pFeature.ShapeCopy
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NearestMToPoint pCurve, pPoint, dMeas, pNearPoint, dNearDist, bRight
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dMeas = Round(dMeas, 0) ' Apply Rounding if desired or comment out
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dFromMeas = pRow.Value(lFromMeas)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dToMeas = pRow.Value(lToMeas)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If dFromMeas &amp;lt; dToMeas And dMeas &amp;gt; dFromMeas And dMeas &amp;lt; dToMeas And dMeas &amp;lt;&amp;gt; -1 Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRowB = pRow
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pRowB.Value(lFromMeas) = dMeas
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pICursor.InsertRow pRowB ' This duplicates the record in the event table.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pRow.Value(lFromMeas) = dFromMeas
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pRow.Value(lToMeas) = dMeas
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pCursor.UpdateRow pRow
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf dFromMeas &amp;gt; dToMeas And dMeas &amp;gt; dToMeas And dMeas &amp;lt; dFromMeas And dMeas &amp;lt;&amp;gt; -1 Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRowB = pRow
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pRowB.Value(lToMeas) = dMeas
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pICursor.InsertRow pRowB ' This duplicates the record in the event table.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pRow.Value(lToMeas) = dToMeas
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pRow.Value(lFromMeas) = dMeas
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pCursor.UpdateRow pRow
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRow = pCursor.NextRow
&amp;nbsp; Loop
End Sub


' Sub to Get Nearest M value, Point on Curve, Distance, and Side of Curve from original Point
Private Sub NearestMToPoint(ByRef pCurve As ICurve, ByRef pPoint As IPoint, _
&amp;nbsp; ByRef dMeas As Double, ByRef pNearPoint As IPoint, ByRef dNearDist As Double, ByRef bRight As Boolean)
&amp;nbsp;&amp;nbsp; ' Set dMeas to a value that is invalid so that result can be tested by calling code
&amp;nbsp;&amp;nbsp; dMeas = -1
&amp;nbsp;&amp;nbsp; ' Validate Minimum input variables
&amp;nbsp;&amp;nbsp; If pCurve Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Err.Raise vbObjectError + 11282003, "NearestMToPoint", "No Input Curve Provided"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp;&amp;nbsp; End If
&amp;nbsp;&amp;nbsp; If pPoint Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Err.Raise vbObjectError + 11282002, "NearestMToPoint", "No Input Point Provided"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub
&amp;nbsp;&amp;nbsp; End If
&amp;nbsp; ' Initialize resulting pNearPoint if it is not already initialized to avoid causing an error
&amp;nbsp;&amp;nbsp; If pNearPoint Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pNearPoint = New Point
&amp;nbsp;&amp;nbsp; End If

&amp;nbsp;&amp;nbsp; ' Make sure input curve is MAware
&amp;nbsp;&amp;nbsp; Dim pMA As IMAware
&amp;nbsp;&amp;nbsp; Set pMA = pCurve
&amp;nbsp;&amp;nbsp; If pMA.MAware Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' initialize variables used to QueryPointAndDistance
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim bAsRatio As Boolean
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bAsRatio = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim dAlong As Double
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pCurve.QueryPointAndDistance esriNoExtension, pPoint, bAsRatio, pNearPoint, dAlong, dNearDist, bRight

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Initialize variables to find the best M value of point
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pMSeg As IMSegmentation
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pMSeg = pCurve
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim Ms As Variant
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ms = pMSeg.GetMsAtDistance(dAlong, bAsRatio)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If UBound(Ms) &amp;gt; 0 Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim iCount As Long
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim lCount As Long
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pGeomColl As IGeometryCollection
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pGeom As IGeometry
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pTestPoint As IPoint
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pTestPoint = New Point
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For iCount = LBound(Ms) To UBound(Ms)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeomColl = pMSeg.GetPointsAtM(Ms(iCount), 0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For lCount = 0 To pGeomColl.GeometryCount - 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeom = pGeomColl.Geometry(lCount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pTestPoint = pGeom
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Make sure the M value returns a Point that matches the point returned by QueryPointAndDistance.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Round(pTestPoint.x, 8) = Round(pNearPoint.x, 8) And Round(pTestPoint.y, 8) = Round(pNearPoint.y, 8) Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dMeas = Ms(iCount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next lCount
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next iCount
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If dMeas = -1 Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Err.Raise vbObjectError + 11282001, "NearestMToPoint", "No M Values Located"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dMeas = Ms(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If
&amp;nbsp;&amp;nbsp; Else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Err.Raise vbObjectError + 11282000, "NearestMToPoint", "Not M Aware"
&amp;nbsp;&amp;nbsp; End If
End Sub&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:24:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/inserting-lr-event-features-with-vba/m-p/274963#M7035</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T13:24:41Z</dc:date>
    </item>
  </channel>
</rss>

