offseting a polyline

offseting a polyline

Anonymous
Not applicable
587 Views
1 Reply
Message 1 of 2

offseting a polyline

Anonymous
Not applicable

Hi i have this code that allows me to draw a box and then create a polyline from it. I then want it to offset I can get it to work but the when i enter the offset distance it seems to offset the line arbitrarily. Its never the distance i provide. 

 

Private Sub CommandButton1_Click()
UserForm2.Hide
Dim pi As Double
Dim pt1(0 To 2) As Double
Dim pt2 As Variant
Dim pt3 As Variant
Dim pt4 As Variant
'With ThisDrawing
'.SendCommand ("select " & "all  ")
'.SendCommand ("erase ")
'End With
pi = 3.14159265358979
pt1(0) = 0#: pt1(1) = 0#: pt1(2) = 0#
    With ThisDrawing.Utility
        pt2 = .PolarPoint(pt1, 0, Val(TextBox1.Text))
        pt3 = .PolarPoint(pt2, pi / 2, Val(TextBox2.Text))
        pt4 = .PolarPoint(pt1, pi / 2, Val(TextBox2.Text))
    End With
    With ThisDrawing.ModelSpace
        .AddLine pt1, pt4
        .AddLine pt4, pt3
        .AddLine pt3, pt2
        .AddLine pt2, pt1
    End With
'ThisDrawing.ModelSpace.AddCircle pt1, Val(TextBox2.Text) / 2
peditAll
offSet
Unload Me
End Sub
Private Sub peditAll()
    ThisDrawing.SendCommand ("PEDIT " & "multiple " & "all  " & "yes " & "join  " & "close  ")
End Sub
Private Sub CommandButton2_Click()
    Unload Me
End Sub
Private Sub offSet()
'
Dim dist As String
dist = TextBox3.Value & " "
ThisDrawing.SendCommand ("select " & "all  ")
ThisDrawing.SendCommand ("offset " & "t " & dist & " ")
End Sub

 as you can see it is a userform and the user puts in length and width and offset distance. If there is a better way to do an offset in this fashion I'm all ears. 

 

Thanks for any help

0 Likes
588 Views
1 Reply
Reply (1)
Message 2 of 2

kasperwuyts
Collaborator
Collaborator

General rule is to always avoid using 'sendcommand' if there is a tool in the com api that does the same job.

 

This assumes that the polyline you want to offset is the latest object that is created (the index number being equal to the number of objects minus one). With your method of creating the polyline, that probably won't work all the time. I would suggest simply creating the polyline at once instead of drawing for lines and joining them.

 

 

Private Sub offSet()

 

Dim Mypline As AcadLWPolyline
Dim dist As String
Dim OffsetObj As Variant

 

Set Mypline = ThisDrawing.ActiveLayout.Block.Item(ThisDrawing.ActiveLayout.Block.Count - 1)
OffsetObj = Mypline.offSet(dist)
Mypline.Delete

 

End Sub

 

 


Best regards
Kasper Wuyts
_______________________________________________________________________________
If this post solves your problem, clicking the 'accept as solution' button would be greatly appreciated.
0 Likes