[求助]将多段线内部的对象提取出来
<p> 效果如<a href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=73592">http://bbs.mjtd.com/forum.php?mod=viewthread&tid=73592</a></p><p>将多段线内部的对象提取出来在新的地方重新生成。</p><p>请问使用VBA怎么开发?</p> <p>这段代码是选择封闭多选段内的实体,生成一个选择集。</p><p>Public Sub SelectByPoly(ByRef SSet As AcadSelectionSet, ByVal objPline As AcadLWPolyline, ByVal mode As AcSelect)<br/> If objPline.Closed = False Then<br/> MsgBox "作为边界的多段线不闭合!"<br/> Exit Sub<br/> End If<br/> <br/> '将轻量多段线的坐标输入到点数组中<br/> Dim pointArrs() As Double<br/> ReDim pointArrs((UBound(objPline.Coordinates) + 1) * 3 / 2 - 1)<br/> <br/> Dim i As Integer<br/> For i = 0 To ((UBound(objPline.Coordinates) + 1) / 2 - 1)<br/> pointArrs(3 * i) = objPline.Coordinates(2 * i)<br/> pointArrs(3 * i + 1) = objPline.Coordinates(2 * i + 1)<br/> pointArrs(3 * i + 2) = 0<br/> Next i<br/> <br/> SSet.SelectByPolygon mode, pointArrs<br/>End Sub</p><p>然后可以拷贝选择集中对象。</p> <p>不错,把POLYLINE的点坐坐标数据都放入了数组中,再以数组中的信息生成POLYLINE</p> <p>将上面的代码再加个实例:把上面的改成一个函数</p><p>Sub atemp()<br/>Dim ss As AcadSelectionSet<br/>Dim ent As AcadEntity<br/>Dim a As AcadLWPolyline<br/>Dim p As Variant<br/>Set ss = ThisDrawing.SelectionSets.Add("sss") '在屏幕上选择筒灯或对象<br/>ThisDrawing.Utility.GetEntity ent, p, "选择一个封闭的多段线"<br/>If ent.ObjectName = "AcDbPolyline" Then<br/> Set a = ent<br/> SelectByPoly ss, a, acSelectionSetWindowPolygon<br/>End If<br/>For Each ent In ss<br/> ent.color = acBlue '这个是测试,在这里加入你的代码<br/>Next<br/>ss.Delete<br/>End Sub<br/></p><p></p><p>Public Function SelectByPoly(ByRef SSet As AcadSelectionSet, ByVal objPline As AcadLWPolyline, ByVal mode As AcSelect)<br/> If objPline.closed = False Then<br/> MsgBox "作为边界的多段线不闭合!"<br/> Exit Function<br/> End If<br/> '将轻量多段线的坐标输入到点数组中<br/> Dim pointArrs() As Double<br/> ReDim pointArrs((UBound(objPline.Coordinates) + 1) * 3 / 2 - 1)<br/> Dim i As Integer<br/> For i = 0 To ((UBound(objPline.Coordinates) + 1) / 2 - 1)<br/> pointArrs(3 * i) = objPline.Coordinates(2 * i)<br/> pointArrs(3 * i + 1) = objPline.Coordinates(2 * i + 1)<br/> pointArrs(3 * i + 2) = 0<br/> Next i<br/> SSet.SelectByPolygon mode, pointArrs<br/>End Function</p>
页:
[1]