今天看见一个用三维多线段作的地形图,没用拟合平滑。这种线,看着闹心,所以写个小代码转成多线段了!
- On Error GoTo err1
- Dim blnDel As Boolean
- blnDel = IIf(MsgBox("是否删除源三维多线段?" & vbCrLf & "提示:如果三维多线段采用'拟合/平滑',转换后不准确!", vbYesNo + vbQuestion, "MEA") = vbYes, True, False)
-
- AppActivate objCad.Caption
- Dim objSset As AcadSelectionSet
- Dim objDoc As AcadDocument
- Set objDoc = ThisDrawing()
- SelectLots "MEA~PL~TMP~123", "POLYLINE" ' 三维多线段
- Set objSset = objDoc.SelectionSets("MEA~PL~TMP~123")
- If objSset.Count = 0 Then Exit Sub
- Dim obj1 As Acad3DPolyline
- Dim objPL As AcadLWPolyline
- Dim coords As Variant, coords2() As Double, dblElv As Double, flag As Boolean
- Dim i As Long, j As Long
- For Each obj1 In objSset
- 'Debug.Print obj1.ObjectName
- flag = False
- dblElv = 0
- i = 0: j = 0
- coords = obj1.Coordinates
- ReDim coords2(CLng((UBound(coords) + 1) / 3 * 2) - 1)
- For i = 0 To UBound(coords)
- If (i + 1) Mod 3 = 0 Then
- If Not flag Then 'z坐标不一致,放弃对标高的转换,全为0
- If i = 2 Then
- dblElv = coords(2)
- Else
- If Abs(dblElv - coords(i)) > 0.00001 Then flag = True: dblElv = 0 '放弃标高
- End If
- End If
- Else
- coords2(j) = coords(i)
- j = j + 1
- End If
- Next i
- Set objPL = objDoc.ModelSpace.AddLightWeightPolyline(coords2)
- objPL.Elevation = dblElv
- objPL.Update
- If blnDel Then obj1.Delete
- Next obj1
- Exit Sub
- err1:
- Err.Clear
- Debug.Print "三维多线段转多线段出错!"
|