laotoule8 发表于 2024-2-7 18:01:20

请教,怎样才能用autolisp在直线两端各加一个矩形?

本人不会autolisp。请教,怎样才能用autolisp在直线两端各加一个矩形?比如在白色直线的两端各加一个1*5的矩形?


bianjun68 发表于 2024-2-8 00:13:47

你是直线先画出,再加矩形,还是画直线的同时,加上矩形,一次完成?

bianjun68 发表于 2024-2-8 18:15:14

我用VBA实现。

bianjun68 发表于 2024-2-8 18:17:12

bianjun68 发表于 2024-2-8 18:18:18

Sub creatEndRect()
   
    Dim line2 As AcadLine
    ThisDrawing.Utility.GetEntity line2, basePnt, "Select an line:"
   
    Dim p1
    p1 = line2.startPoint
    Dim p2
    p2 = line2.endPoint
   
    Dim angle2 As Double
    angle2 = line2.angle

    Dim pts1(0 To 7) As Double
    Dim pts2(0 To 7) As Double
      
    pts1(0) = CDbl(p1(0)) + 0.5 * Sin(angle2): pts1(1) = CDbl(p1(1)) - 0.5 * Cos(angle2)
    pts1(2) = pts1(0) + 5 * Cos(angle2): pts1(3) = pts1(1) + 5 * Sin(angle2)
    pts1(4) = pts1(2) - 1 * Sin(angle2): pts1(5) = pts1(3) + 1 * Cos(angle2)
    pts1(6) = pts1(4) - 5 * Cos(angle2): pts1(7) = pts1(5) - 5 * Sin(angle2)
   
    pts2(0) = CDbl(p2(0)) + 0.5 * Sin(angle2): pts2(1) = CDbl(p2(1)) - 0.5 * Cos(angle2)
    pts2(2) = pts2(0) - 5 * Cos(angle2): pts2(3) = pts2(1) - 5 * Sin(angle2)
    pts2(4) = pts2(2) - 1 * Sin(angle2): pts2(5) = pts2(3) + 1 * Cos(angle2)
    pts2(6) = pts2(4) + 5 * Cos(angle2): pts2(7) = pts2(5) + 5 * Sin(angle2)
   
    Dim pl0 As AcadLWPolyline
    Set pl0 = ThisDrawing.ModelSpace.AddLightWeightPolyline(pts1)
    Dim pl1 As AcadLWPolyline
    Set pl1 = ThisDrawing.ModelSpace.AddLightWeightPolyline(pts2)

    pl0.Closed = True
    pl1.Closed = True

End Sub

bianjun68 发表于 2024-2-12 08:21:21

不客气!管用就好!
页: [1]
查看完整版本: 请教,怎样才能用autolisp在直线两端各加一个矩形?