cad vba 如何获取多段线xyz 的坐标并存在一个txt文档里

2024-11-27 08:15:39
推荐回答(2个)
回答1:

Private Sub GetLWPOLYLINECoordinates()
Dim ss_dim As AcadSelectionSet, ent As AcadLWPolyline
Dim dxf_code() As Integer, dxf_value() As Variant
Dim i As Long, 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

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, "X" & x & ",Y" & y
Next
Next
Close #1
ss_dim.Clear
ss_dim.Delete
End Sub

回答2:

没有Z就没有吧。polyline的坐标信息里好像就不包含Z,忍了吧。