程序的目的是将3D多段线的所有节点的Z坐标去掉,然后生成一2D多段线。思路应该没有问题,可老提示坐标越界。哪位帮我看看到底是怎么回事。 用下面这个图形做测试。- Sub test3Dto2D()
- '创建选择集
- Dim selset As AcadSelectionSet
- Dim cor3 As Variant
- Dim n As Integer
- Dim a As Integer
- a = 0
- Set selset = ThisDrawing.SelectionSets.Add("sset")
- selset.Select acSelectionSetAll '遍历选择集并将每一个对象镜相
- Dim entry As AcadObject
- Dim pl As AcadLWPolylineFor Each entry In selset
- If entry.EntityName = "AcDb3dPolyline" Then
- cor3 = entry.Coordinates
- n = (UBound(cor3) + 1) * 2 / 3
- Dim pt() As Double
- ReDim pt(0 To n - 1) As Double For i = 0 To (n - 2) Step 2
- pt(i) = cor3(a)
- pt(i + 1) = cor3(a + 1)
- a = a + 3
- Next i
-
- Set pl = ThisDrawing.ModelSpace.AddLightWeightPolyline(pt)
- entry.Delete
- End If
- Next entryselset.Delete '避免下次重复End Sub
|