井井井1314 发表于 2019-7-4 10:18:05

新手求助

路过的师傅给看看 红色的两条是什么意义,有没有好像一样的

Public Function AddPlineSeg(ByVal ptSt As Variant, ByVal ptEn As Variant, ByVal width As Double) As AcadPolyline
    Dim objPline As AcadPolyline
    Dim ptArr(0 To 5) As Double

    ptArr(0) = ptSt(0)
    ptArr(1) = ptSt(1)
    ptArr(2) = ptSt(2)
    ptArr(3) = ptEn(0)
    ptArr(4) = ptEn(1)
    ptArr(5) = ptEn(2)

    Set objPline = ThisDrawing.ModelSpace.AddPolyline(ptArr)
    objPline.ConstantWidth = width
    objPline.Update
   
    Set AddPlineSeg = objPline
End Function


井井井1314 发表于 2019-7-4 10:27:37

路过的老师 这个地方为什么是 (i\2)

Public Function AddPolygon(ByVal ptcen As Variant, ByVal number As Integer, ByVal radius As Date, Optional width As Double, Optional angle As Double = 0) As AcadLWPolyline
'定义动态数组
    Dim objPline As AcadLWPolyline
    Dim ptArr() As Double
    '顶点的个数为number,需要2*number个元素来表示
    ReDim ptArr(2 * number - 1)
   
    '每条边对应的角度
    Dim ang As Double
    ang = 2 * 3.1415926 / number
   
    '为点的坐标数组赋值
    Dim i As Integer
    For i = 0 To 2 * number - 1
      If i Mod 2 = 0 Then
            ptArr(i) = ptcen(0) + radius * Cos((i \ 2) * ang)
      ElseIf i Mod 2 <> 0 Then
            ptArr(i) = ptcen(1) + radius * Sin((i \ 2) * ang)
      End If
    Next i
      
    '创建多段线,并调整其特性
    Set objPline = AddLWPline(ptArr, width)
    objPline.Closed = True
    objPline.Rotate ptcen, angle
    objPline.Update
End Function

mikewolf2k 发表于 2019-7-4 11:08:25

不加最后这句,function返回不了值。

mikewolf2k 发表于 2019-7-4 11:11:02

井井井1314 发表于 2019-7-4 10:27
路过的老师 这个地方为什么是 (i\2)

Public Function AddPolygon(ByVal ptcen As Variant, ByVal number ...

数组的顶点列表是xy混在一起的,1/2是第一点的x/y, 3/4是第二点的x/y,所以要除以2取整才能获得相应的x/y。
页: [1]
查看完整版本: 新手求助