' polyline offset  dh42 2015
'
'creates and select ONE polyline before running the script
' 2 polylines will be created, one external and one internal + corner overcut
'
Sub main()
    CamBam.CamBamConfig.Defaults.ReloadTreeAfterScript = False
    Dim poly As Polyline
    'only one polyline selected
    If CamBamUI.MainUI.ActiveView.SelectedEntities.Length = 1 Then
        For Each ent As Entity In CamBamUI.MainUI.ActiveView.SelectedEntities
            If TypeOf ent Is Polyline Then
                poly = CType(ent, Polyline)
                '--------------------------------------

                offset1(poly)   'create a simple offset polyline

                offset2(poly)   'create an offset polyline with corner overcut

                '--------------------------------------
            Else
                App.Log("select only ONE polyline")
            End If
        Next ent
        CamBamUI.MainUI.ActiveView.RefreshView()
    End If

End Sub

Sub offset1(p As Polyline)
    Dim p1() As Polyline 'an array of polylines

    'creates an array of polylines offseted from the source polyline
    'the resulting polyline is in the first element of the array
    p1 = p.CreateOffsetPolyline(10.5, 0.01)

    Try
        Doc.Add(p1(0))  'add the first element of the array to the doc (the offseted polyline)
    Catch ex As Exception
        App.Log("unable to offset this polyline")
    End Try


End Sub

Sub offset2(p As Polyline)
    Dim p1() As Polyline 'an array of polylines

    p1 = p.CreateOffsetPolyline(-2.5, 0.01, True, False)

    Try
        doc.add(p1(0))  'add the first element of the array to the doc (the offseted polyline)
    Catch ex As Exception
        App.Log("unable to offset this polyline")
    End Try
End Sub