明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3205|回复: 4

[原创]刚完成的VB-返回多段线顶点坐标的代码

[复制链接]
发表于 2007-1-10 20:43 | 显示全部楼层 |阅读模式

Private Sub cd多段线坐标查询_Click()
    On Error Resume Next
    '安全创建选择集
    If Not IsNull(AcadApp.ActiveDocument.SelectionSets.Item("Test")) Then
        Set ssetObj = AcadApp.ActiveDocument.SelectionSets.Item("Test")
        ssetObj.Delete
    End If
    '创建选择集
    Set ssetObj = AcadApp.ActiveDocument.SelectionSets.add("Test")
    '激活CAD窗口
    AppActivate AcadApp.Caption
    AcadApp.WindowState = acMax
    '提示用户从屏幕选择实体对象,并加入选择集
    ssetObj.SelectOnScreen
    '选择完毕后按回车键或单击右键
    Dim pickedObjs As AcadEntity
    Dim retCoord As Variant
    For Each pickedObjs In ssetObj
        retCoord = pickedObjs.Coordinates
        AppActivate Me.Caption
        AcadApp.WindowState = acMin
        If TypeOf pickedObjs Is AcadPolyline Or TypeOf pickedObjs Is Acad3DPolyline Then   '普通多义线或3维多段线
            j = (UBound(pickedObjs.Coordinates) + 1) / 3   '多义线的顶点数
            For i = 0 To j * 3 - 1 Step 3                    If retCoord(0) = retCoord(j * 3 - 3) And retCoord(1) = retCoord(j * 3 - 2) Then  '闭合时
                        MSFlexGrid1.Rows = j
                    Else   '非闭合时
                        MSFlexGrid1.Rows = j + 1
                    End If
                    MSFlexGrid1.TextMatrix(i / 3 + 1, 0) = i / 3 + 1
                    MSFlexGrid1.TextMatrix(i / 3 + 1, 2) = Format(retCoord(i) / 1000 * Val(Text比例.Text), "0.000")
                    MSFlexGrid1.TextMatrix(i / 3 + 1, 1) = Format(retCoord(i + 1) / 1000 * Val(Text比例.Text), "0.000")           

            Next i
        ElseIf TypeOf pickedObjs Is AcadLWPolyline Then   '轻便多义线
            j = (UBound(pickedObjs.Coordinates) + 1) / 2   '多义线的顶点数
            For i = 0 To j * 2 - 1 Step 2                    If retCoord(0) = retCoord(j * 2 - 2) And retCoord(1) = retCoord(j * 2 - 1) Then '闭合时
                        MSFlexGrid1.Rows = j
                    Else   '非闭合时
                        MSFlexGrid1.Rows = j + 1
                    End If
                    MSFlexGrid1.TextMatrix(i / 2 + 1, 0) = i / 2 + 1
                    MSFlexGrid1.TextMatrix(i / 2 + 1, 2) = Format(retCoord(i) / 1000 * Val(Text比例.Text), "0.000")
                    MSFlexGrid1.TextMatrix(i / 2 + 1, 1) = Format(retCoord(i + 1) / 1000 * Val(Text比例.Text), "0.000")

            Next i
        Else
             MsgBox "您选择的不是多段线!", 64 + vbOKOnly, "地质测量"
             ssetObj.Delete
        End If
        Exit For
    Next
    '删除选择集
    ssetObj.Delete
End Sub

评分

参与人数 1明经币 +1 收起 理由
mccad + 1 【好评】表扬一下

查看全部评分

发表于 2007-1-18 13:54 | 显示全部楼层
DUOXIEA
发表于 2013-4-19 17:07 | 显示全部楼层
收藏多段线顶点坐标
发表于 2013-4-25 01:08 | 显示全部楼层
收下了。。留给以后用
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-25 07:23 , Processed in 0.295104 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表