想用VB怎么实现以下问题--将CAD中多段线按距离平均分段,然后提取各分段点坐标?
发布网友
发布时间:2022-04-23 12:31
我来回答
共1个回答
热心网友
时间:2023-10-13 11:45
两种办法
第一种手工用鼠标选择多段线,然后输入list命令,弹出一个窗口,然后复制那些坐标,粘到excel里面,在exel里面根据空格来分列,最后得到X,Y的数值
第二种就麻烦一些了,建立一个选择集,用lisp或者vba来写一个提取多段线的代码。我这里有网上的一个vba代码,如果你不会vba的话,最好不要用。
Option Explicit
Public Sub GetLWPOLYLINECoordinates()
Dim ss_dim As AcadSelectionSet, ent As AcadLWPolyline
Dim dxf_code() As Integer, dxf_value() As Variant
'Dim i As Long,
Dim j As Long
Dim dbCor As Variant, x As Double, y As Double, z As Double
Set ss_dim = ThisDrawing.SelectionSets.Add("ssLine1")
ReDim dxf_code(0), dxf_value(0)
dxf_code(0) = 0: dxf_value(0) = "LWPOLYLINE"
'ss_dim.Select acSelectionSetAll, , , dxf_code, dxf_value
ss_dim.SelectOnScreen dxf_code, dxf_value
Open "d:\aaaaa.txt" For Append As #1
For Each ent In ss_dim
For j = 0 To UBound(ent.Coordinates) \ 2
x = ent.Coordinates(j * 2)
y = ent.Coordinates(j * 2 + 1)
Print #1, (j); ",," & x & "," & y
Next
Next
Stop
Close #1
ss_dim.Clear
ss_dim.Delete
End Sub