将上面的代码再加个实例:把上面的改成一个函数 Sub atemp() Dim ss As AcadSelectionSet Dim ent As AcadEntity Dim a As AcadLWPolyline Dim p As Variant Set ss = ThisDrawing.SelectionSets.Add("sss") '在屏幕上选择筒灯或对象 ThisDrawing.Utility.GetEntity ent, p, "选择一个封闭的多段线" If ent.ObjectName = "AcDbPolyline" Then Set a = ent SelectByPoly ss, a, acSelectionSetWindowPolygon End If For Each ent In ss ent.color = acBlue '这个是测试,在这里加入你的代码 Next ss.Delete End Sub
Public Function SelectByPoly(ByRef SSet As AcadSelectionSet, ByVal objPline As AcadLWPolyline, ByVal mode As AcSelect) If objPline.closed = False Then MsgBox "作为边界的多段线不闭合!" Exit Function End If '将轻量多段线的坐标输入到点数组中 Dim pointArrs() As Double ReDim pointArrs((UBound(objPline.Coordinates) + 1) * 3 / 2 - 1) Dim i As Integer For i = 0 To ((UBound(objPline.Coordinates) + 1) / 2 - 1) pointArrs(3 * i) = objPline.Coordinates(2 * i) pointArrs(3 * i + 1) = objPline.Coordinates(2 * i + 1) pointArrs(3 * i + 2) = 0 Next i SSet.SelectByPolygon mode, pointArrs End Function |