当前版块:问答社区 > CASS

[CASS二次开发源代码]VB6+AutoCAD多段线换向

Windows10
其他
CASS9
Sub IReversal(ByVal AcadApp As Object) '多段线换向
    Dim ent As Object
    Dim pnt As Variant, NewCoord() As Double, i As Integer
    Dim Coord As Variant, CoordCount As Integer, Bulge() As Double
    On Error Resume Next
    AcadApp.Application.ActiveDocument.Utility.GetEntity ent, pnt, vbCr & vbCr & "指定多段线:"
    If Err Then Err.Clear: Exit Sub
    If TypeName(ent) = "IAcadLWPolyline" Then
        Coord = ent.Coordinates
        CoordCount = (UBound(Coord) + 1) / 2
        ReDim NewCoord(UBound(Coord)) As Double
        For i = 0 To UBound(Coord) - 1 Step 2
            NewCoord(UBound(Coord) - i - 1) = Coord(i)
            NewCoord(UBound(Coord) - i) = Coord(i + 1)
        Next
        ReDim Bulge(CoordCount - 1) As Double
        For i = 0 To CoordCount - 1
            Bulge(i) = ent.GetBulge(i)
        Next
        ent.Coordinates = NewCoord
        For i = 0 To CoordCount - 2
            ent.SetBulge i, -Bulge(CoordCount - 2 - i)
        Next
        AcadApp.Application.ActiveDocument.Regen 1
    ElseIf TypeName(ent) = "IAcadPolyline" Then
        Coord = ent.Coordinates
        CoordCount = (UBound(Coord) + 1) / 3
        ReDim NewCoord(UBound(Coord)) As Double
        For i = 0 To UBound(Coord) - 1 Step 3
            NewCoord(UBound(Coord) - i - 2) = Coord(i)
            NewCoord(UBound(Coord) - i - 1) = Coord(i + 1)
            NewCoord(UBound(Coord) - i) = Coord(i + 2)
        Next
        If ent.Type = acSimplePoly Then
            ReDim Bulge(CoordCount - 1) As Double
            For i = 0 To CoordCount - 1
                Bulge(i) = ent.GetBulge(i)
            Next
        End If
        ent.Coordinates = NewCoord
        If ent.Type = acSimplePoly Then
            For i = 0 To CoordCount - 2
                ent.SetBulge i, -Bulge(CoordCount - 2 - i)
            Next
        End If
        AcadApp.Application.ActiveDocument.Regen 1
    Else
        MsgBox "不支持的实体类型。", vbExclamation, "AutoCAD"
    End If
End Sub

全部评论

等级:LV30
积分:72050
奔跑蜗牛 2019-12-03 16:30
大神厉害
回复 0
1
提交
悬赏回复规则
1、悬赏期为24小时,从发布时间起算;
2、悬赏期内提问者如设置评论为“精选评论”,视为悬赏结束,该精选评论人将获得本题全部悬赏积分;
3、悬赏期内如提问者未设置“精选评论”,则前5位评论者平分悬赏积分(如仅有一位评论,该评论者获得50%悬赏积分);
4、悬赏积分会自动发放到生态圈账户中,请留意站内信通知。
知道了

距离打开宝箱还剩7

是否花费200积分补签?
确认
取消