Parallel Polylines with VBA

690
5
09-23-2010 11:51 AM
LawrenceHughes
New Contributor
Hi

I have a VBA routine, where the user clicks on a polyline and the coordinates are returned. X1, Y1, X2 and Y2. I also have a routine to draw a line between these coordinates. How do I draw the polyline parallel to the original line, which is offset by the same distance, regardless of the zoom factor?

Thanks in advance.

Lawrence
0 Kudos
5 Replies
NeilClemmons
Regular Contributor III
Use IConstructCurve.ConstructOffset.
0 Kudos
LawrenceHughes
New Contributor
Hi Neil

After a lot of surfing around, I found the following example:

______________

Private Function ConstructOffset(pInPolyline As IPolyline, dOffset As Double) As IPolyline
Dim pConstructCurve As IConstructCurve
On Error GoTo ErrorHandler
If pInPolyline Is Nothing Or pInPolyline.IsEmpty Then Exit Function
Set pConstructCurve = New Polyline
pConstructCurve.ConstructOffset pInPolyline, dOffset, esriConstructOffsetRounded + esriConstructOffsetSimple
Set ConstructOffset = pConstructCurve
Exit Function
ErrorHandler:
Set ConstructOffset = Nothing
End Function
______________

Here is my line drawing function. I can't get my function to correctly call the above function. Can you see what is wrong?

Many thanks

______________

Private Function DrawLine(x1, y1, x2, y2, aView As IActiveView, pMap, LineName)

On Error GoTo err_handler

Dim pPointCollection As IPointCollection
Dim pFromPoint As ipoint
Dim pToPoint As ipoint
Dim pPolyline As IPolyline
Set pFromPoint = New Point
Set pToPoint = New Point
Dim pLineSym As ISimpleLineSymbol
Dim pLineElement As ILineElement

pFromPoint.PutCoords x1, y1
pToPoint.PutCoords x2, y2
Set pPolyline = New Polyline

Set pPointCollection = New Polyline
Set oPointCollection = New Polyline
pPointCollection.AddPoint pFromPoint
pPointCollection.AddPoint pToPoint

Dim pGC As IGraphicsContainer
Set pGC = pMap

Dim pElement As IElement
Dim oElement As IElement
Dim oLineElement As ILineElement
Set pElement = New LineElement
Set oElement = New LineElement

pElement.Geometry = pPointCollection

Dim oLineSym As ISimpleLineSymbol
Dim SymCol As IRgbColor
Set pLineElement = pElement
Set oLineElement = oElement
Set pLineSym = New SimpleLineSymbol
pLineSym.Style = esriSLSSolid
pLineSym.Width = 3
Set SymCol = New RgbColor
SymCol.Blue = 255
pLineSym.Color = SymCol
pLineElement.Symbol = pLineSym

oLineElement = ConstructOffset(pPointCollection, 100)

Dim elemProps As IElementProperties
Set elemProps = pLineElement
elemProps.Name = LineName
       
pGC.AddElement pLineElement, 0
pGC.AddElement oLineElement, 0

aView.PartialRefresh esriViewGraphics, Nothing, Nothing

Exit Function
err_handler:
MsgBox Err & " - " & Error$
Resume
End Function

______________
0 Kudos
NeilClemmons
Regular Contributor III
Your ConstructOffset function returns a polyline.  You're trying to set a line element equal to that polyline.  That won't work as it is a type mismatch.  You need to set your element's geometry to be the polyline returned by the ConstructOffset function.
0 Kudos
LawrenceHughes
New Contributor
Sorry Neil (or anyone else), my last reply should have read, how can I change my code to return a polyline and not an element? I am struggling with the concepts here.

Many thanks
0 Kudos
LawrenceHughes
New Contributor
Hi

The above code is now working. What I really need is to create two parallel lines, which stay the same distance apart whether the user zooms in or out. Is this possible?

Regards

Lawrence
0 Kudos