有两种方式:
注意:两点线如果距离小于0.1,则删除;且两点线不参加判断。
废话少说,贴代码啊!
Option Explicit
'正确的删除复合线多余结点过程
'错误的见DelOverlayVertex_Wrong过程
'但是DelOverlayVertex_Wrong能一次得到一组正确的坐标
Public Sub DelOverlayVertex()
'On Error Resume Next
'定义选择集
Dim LwPOlvtSelset As AcadSelectionSet
Set LwPOlvtSelset = CreateSelectionSet
'建立选择集过滤器
Dim TypeArray As Variant
Dim DateArray As Variant
BuildFilter TypeArray, DateArray, 0,
"LWPOLYLINE", 8, "jmd"
LwPOlvtSelset.Select acSelectionSetAll, , ,
TypeArray, DateArray
Dim LwPOlvt As AcadLWPolyline
Dim i As Integer
'选择集的个数
Dim k As Integer
'单个lwpolyline的结点
'定义新旧结点
Dim PtVtxOld As Variant
Dim NewVtxCor() As Double
ReDim Preserve NewVtxCor(1)
'定义新坐标数组上维
Dim UBound_K As Integer
Dim d As
Double '定义结点距离
Dim PtVtxAX As Double
Dim PtVtxAY As Double
Dim PtVtxAftAX As Double
Dim PtVtxAftAY As Double
For i = 0 To LwPOlvtSelset.Count - 1
Set LwPOlvt = LwPOlvtSelset.Item(i)
PtVtxOld = LwPOlvt.Coordinates
Dim m As Integer
m =
UBound(PtVtxOld)
'第一次得到复合线上结点的个数
'一组数据进行循环
For k = 2 To m Step 2
'线的长度小于规定值0.1,则删除这条线
If LwPOlvt.Length < 0.1 Then LwPOlvt.Delete
If k > m Then GoTo Do_Next
'如果是两点线,则跳出循环
If (m + 1) / 2 = 2 Then GoTo Do_Next
'得到线实体的坐标数组
PtVtxOld = LwPOlvt.Coordinates
'第一个结点的坐标赋值给新坐标数组
NewVtxCor(0) = PtVtxOld(0)
NewVtxCor(1) = PtVtxOld(1)
PtVtxAX = PtVtxOld(k - 2): PtVtxAY = PtVtxOld(k - 1)
'新坐标数组的末尾
'PtVtxAX = NewVtxCor(UBound(NewVtxCor()) - 1): PtVtxAY =
NewVtxCor(UBound(NewVtxCor()))
PtVtxAftAX = PtVtxOld(k): PtVtxAftAY = PtVtxOld(k + 1)
d = Distance(PtVtxAX, PtVtxAftAX, PtVtxAY, PtVtxAftAY)
'如果两结点距离小于规定值0.1,重新定义新坐标数组的维数
Dim n As Integer
If d < 4 Then
UBound_K = UBound(PtVtxOld) - 2
ReDim Preserve NewVtxCor(UBound_K)
For n = k To UBound_K
NewVtxCor(n) = PtVtxOld(n + 2)
Next n