xyz2009xyz 发表于 2010-8-11 21:52:00

[求助][讨论]这段连接线的代码为什么会出现如下的错误窗口

<p><font face="Verdana">这段连接线的代码为什么会出现如下的错误窗口,框选连接时才会出现,点选不会。</font></p>
<p><font face="Verdana">Sub uniteSS()<br/>&nbsp; 'On Error Resume Next<br/>&nbsp; Dim ssetObj As AcadSelectionSet<br/>&nbsp; Set ssetObj = CreateSelectionSet("uniteSS")<br/>&nbsp; Dim fType, fData<br/>&nbsp; BuildFilter fType, fData, -4, "&lt;or", 0, "line", 0, "LWPolyline", -4, "or&gt;"<br/>&nbsp; '屏选直线或多段线<br/>&nbsp; ssetObj.SelectOnScreen fType, fData<br/>&nbsp; Dim i As Integer<br/>&nbsp; If ssetObj.Count &lt;= 1 Then<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.Prompt "选择的线少于两个,退出命令。"<br/>&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp; End If<br/>&nbsp; <br/>&nbsp; Dim line1 As Object<br/>&nbsp; Dim line2 As Object<br/>&nbsp; <br/>&nbsp; Set line1 = ssetObj(0)<br/>&nbsp; Dim pd As Boolean<br/>&nbsp; For i = 1 To ssetObj.Count<br/>&nbsp;&nbsp;&nbsp; Set line2 = ssetObj(i)<br/>&nbsp;&nbsp;&nbsp; '连接线<br/>&nbsp;&nbsp;&nbsp; pd = unite2Line(line1, line2)<br/>&nbsp;&nbsp;&nbsp; '如果连接不成功,则退出命令。<br/>&nbsp;&nbsp;&nbsp; If Not pd Then ssetObj.Delete: Exit Sub<br/>&nbsp; Next<br/>&nbsp; ssetObj.Delete<br/>End Sub</font></p>
<p><font face="Verdana"></font>&nbsp;</p>
<p><font face="Verdana">Sub uniteline()<br/>&nbsp; On Error Resume Next<br/>&nbsp; '取得线<br/>&nbsp; Dim line1 As Object<br/>&nbsp; Dim line2 As Object<br/>&nbsp; Dim pt1, pt2, pt3, pt4, basePnt As AcadEntity<br/>&nbsp; Dim lpt1, lpt2 As Variant<br/>&nbsp; <br/>&nbsp; gwGetEntity line1, basePnt, "请选择第一根直线或多段线:", "AcDbLine", "AcDbPolyline"<br/>&nbsp; If line1 Is Nothing Then<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.Prompt "用户取消,退出命令。"<br/>&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp; End If<br/>&nbsp; <br/>&nbsp; gwGetEntity line2, basePnt, "请选择第二根直线或多段线:", "AcDbLine", "AcDbPolyline"<br/>&nbsp; If line2 Is Nothing Then<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.Prompt "用户取消,退出命令。"<br/>&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp; End If<br/>&nbsp; '连接线<br/>&nbsp; unite2Line line1, line2<br/>End Sub</font></p><font face="Verdana">
<p><br/>Function unite2Line(ByRef line1 As Object, ByVal line2 As Object) As Boolean<br/>&nbsp; '连接线函数,连接后的线返回到变量line1中,如果连接成功,unite2Line返回true,否则为false<br/>&nbsp; On Error Resume Next<br/>&nbsp; unite2Line = False<br/>&nbsp; <br/>&nbsp; If line1.Handle = line2.Handle Then<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.Prompt "选择的是同一直线或多段线,退出命令。"<br/>&nbsp;&nbsp;&nbsp; Exit Function<br/>&nbsp; End If<br/>&nbsp; <br/>&nbsp; getLinePoint line1, pt1, pt2<br/>&nbsp; getLinePoint line2, pt3, pt4<br/>&nbsp; <br/>&nbsp; Dim A1, A2, A3 As Double<br/>&nbsp; Dim maxdi As Double<br/>&nbsp; A1 = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)<br/>&nbsp; A2 = ThisDrawing.Utility.AngleFromXAxis(pt3, pt4)<br/>&nbsp; A3 = ThisDrawing.Utility.AngleFromXAxis(pt1, pt3)<br/>&nbsp; '判断四点是否共线<br/>&nbsp; If Abs(A1 - A2) &lt; 0.0000001 And (Abs(A1 - A3) &lt; 0.0000001 Or Abs(Abs(A1 - A3) - PI) &lt; 0.0000001) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '取得距离最远的两个点。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxdi = MaxDouble(GetDistance(pt1, pt2), GetDistance(pt1, pt3), GetDistance(pt1, pt4), _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetDistance(pt2, pt3), GetDistance(pt2, pt4), GetDistance(pt3, pt4))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If GetDistance(pt1, pt2) = maxdi Then lpt1 = pt1: lpt2 = pt2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If GetDistance(pt1, pt3) = maxdi Then lpt1 = pt1: lpt2 = pt3<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If GetDistance(pt1, pt4) = maxdi Then lpt1 = pt1: lpt2 = pt4<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If GetDistance(pt2, pt3) = maxdi Then lpt1 = pt2: lpt2 = pt3<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If GetDistance(pt2, pt4) = maxdi Then lpt1 = pt2: lpt2 = pt4<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If GetDistance(pt3, pt4) = maxdi Then lpt1 = pt3: lpt2 = pt4<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '画直线<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select Case line1.ObjectName<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case "AcDbLine"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line1.StartPoint = lpt1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line1.EndPoint = lpt2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line2.Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.Prompt "线段已连接为直线."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unite2Line = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case "AcDbPolyline"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim newPline As AcadLWPolyline<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set newPline = AddLWPlineSeg(lpt1, lpt2, line1.ConstantWidth)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newPline.Layer = line1.Layer<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newPline.color = line1.color<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newPline.Linetype = line1.Linetype<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line1.Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line2.Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set line1 = newPline<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.Prompt "线段已连接为多段线."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unite2Line = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Select<br/>&nbsp; Else: ThisDrawing.Utility.Prompt "两线不在同一直线上,退出命令."<br/>&nbsp; End If<br/>End Function<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>'以下是上述代码调用的函数</p>
<p><br/>'创建轻量多段线(只有两个顶点的直线多段线)<br/>Public Function AddLWPlineSeg(ByVal ptSt As Variant, ByVal ptEn As Variant, Optional ByVal width As Double = 0) As AcadLWPolyline<br/>&nbsp;&nbsp;&nbsp; Dim objPline As AcadLWPolyline<br/>&nbsp;&nbsp;&nbsp; Dim ptArr(0 To 3) As Double<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ptArr(0) = ptSt(0)<br/>&nbsp;&nbsp;&nbsp; ptArr(1) = ptSt(1)<br/>&nbsp;&nbsp;&nbsp; ptArr(2) = ptEn(0)<br/>&nbsp;&nbsp;&nbsp; ptArr(3) = ptEn(1)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set objPline = ThisDrawing.ModelSpace.AddLightWeightPolyline(ptArr)<br/>&nbsp;&nbsp;&nbsp; objPline.ConstantWidth = width<br/>&nbsp;&nbsp;&nbsp; objPline.Update<br/>&nbsp;&nbsp;&nbsp; Set AddLWPlineSeg = objPline<br/>End Function<br/>Public Function getLinePoint(ent As AcadEntity, ByRef Point1 As Variant, ByRef Point2 As Variant)<br/>&nbsp;&nbsp;&nbsp;&nbsp; '本函数得到线的端点,其中point1为Y坐标较小的点<br/>&nbsp;&nbsp;&nbsp; Dim p1(2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim p2(2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim k As Integer<br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select Case ent.ObjectName<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case "AcDbLine"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point1 = ent.StartPoint<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point2 = ent.EndPoint<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ThisDrawing.Utility.AngleFromXAxis(Point1, Point2) &gt;= PI Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point1 = ent.EndPoint<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point2 = ent.StartPoint<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case "AcDbPolyline"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim entCo As Variant<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entCo = ent.Coordinates<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k = UBound(entCo)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If k &gt;= 3 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1(0) = entCo(0): p1(1) = entCo(1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p2(0) = entCo(k - 1): p2(1) = entCo(k)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ThisDrawing.Utility.AngleFromXAxis(p1, p2) &gt;= PI Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p2(0) = entCo(0): p2(1) = entCo(1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1(0) = entCo(k - 1): p1(1) = entCo(k)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point1 = p1: Point2 = p2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Select<br/>End Function<br/>Public Function PI() As Double<br/>&nbsp; PI = Atn(1) * 4<br/>End Function<br/>Public Sub GetEntityEx(ent As Object, pickedPoint, Optional Prompt)<br/>&nbsp; '选择实体,直到用户取消操作<br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>StartLoop:<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.GetEntity ent, pt, Prompt<br/>&nbsp;&nbsp;&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ThisDrawing.GetVariable("errno") = 7 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GoTo StartLoop<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Raise vbObjectError + 5, , "用户取消操作"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; End If<br/>End Sub<br/>Public Sub gwGetEntity(ent As Object, pickedPoint, Prompt As String, ParamArray gType())<br/>&nbsp;'选择某一类型的实体,如果选择错误则继续,按ESC退出<br/>&nbsp;'gtype是实体名称,不区分大小写,可以用通配符号,如"AcDbBlockReference","acdb*text"等<br/>&nbsp;Dim i As Integer<br/>&nbsp;Dim pd As Boolean<br/>&nbsp;pd = False<br/>&nbsp;Do<br/>&nbsp; GetEntityEx ent, pickedPoint, Prompt<br/>&nbsp; <br/>&nbsp; If ent Is Nothing Then<br/>&nbsp;&nbsp;&nbsp; Exit Do<br/>&nbsp; ElseIf UBound(gType) - LBound(gType) + 1 = 0 Then<br/>&nbsp;&nbsp;&nbsp; Exit Do<br/>&nbsp; Else<br/>&nbsp;&nbsp;&nbsp; For i = LBound(gType) To UBound(gType)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If UCase(ent.ObjectName) Like UCase(gType(i)) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Do<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pd = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Next i<br/>&nbsp;&nbsp;&nbsp; If pd Then ThisDrawing.Utility.Prompt "选择的实体不符合要求."<br/>&nbsp; End If<br/>&nbsp;Loop<br/>&nbsp;<br/>End Sub<br/>'计算两点之间距离<br/>Public Function GetDistance(sp As Variant, ep As Variant) As Double<br/>&nbsp;&nbsp;&nbsp; Dim x As Double<br/>&nbsp;&nbsp;&nbsp; Dim y As Double<br/>&nbsp;&nbsp;&nbsp; Dim z As Double<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; x = sp(0) - ep(0)<br/>&nbsp;&nbsp;&nbsp; y = sp(1) - ep(1)<br/>&nbsp;&nbsp;&nbsp; z = sp(2) - ep(2)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; GetDistance = Sqr((x ^ 2) + (y ^ 2) + (z ^ 2))<br/>End Function<br/>'返回两个Double类型变量的最大值<br/>Public Function MaxDouble(ByVal a As Double, ParamArray b()) As Double<br/>&nbsp; MaxDouble = a<br/>&nbsp; Dim i As Integer<br/>&nbsp; For i = LBound(b) To UBound(b)<br/>&nbsp;&nbsp;&nbsp; If b(i) &gt; MaxDouble Then MaxDouble = b(i)<br/>&nbsp; Next i<br/>End Function<br/>Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet<br/>&nbsp; '返回一个空白选择集<br/>&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim ss As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; Set ss = ThisDrawing.SelectionSets(ssName)<br/>&nbsp;&nbsp;&nbsp; If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)<br/>&nbsp;&nbsp;&nbsp; ss.Clear<br/>&nbsp;&nbsp;&nbsp; Set CreateSelectionSet = ss<br/>End Function<br/>Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes())<br/>&nbsp;&nbsp;&nbsp; '用数组方式填充一对变量以用作为选择集过滤器使用<br/>&nbsp;&nbsp;&nbsp; Dim fType() As Integer, fData()<br/>&nbsp;&nbsp;&nbsp; Dim index As Long, i As Long<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; index = LBound(gCodes) - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; For i = LBound(gCodes) To UBound(gCodes) Step 2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; index = index + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim Preserve fType(0 To index)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim Preserve fData(0 To index)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fType(index) = CInt(gCodes(i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fData(index) = gCodes(i + 1)<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; typeArray = fType: dataArray = fData<br/>End Sub</p>
<p></font>&nbsp;</p>

xyz2009xyz 发表于 2010-8-11 21:56:00

希望有高手解答,这是合并(连接)一条直线上的两条线的程序。//subtlationuniteSS为框选。uniteline为一根一根选择(只能选择两根)。对多段线和直线都有效。

xyz2009xyz 发表于 2010-8-11 22:29:00

<p>希望大虾们多多帮助,框选一直有错误:<font face="Verdana">线段已连接为直线.执行错误</font>&nbsp; CAD2004版本的</p>

AirCD 发表于 2010-8-12 10:12:00

<p>楼主犯了一个很常见的错误:在每次程序运行前应判断目标选择集(即本程序代码中的uniteSS)是否已存在,若是的话应先删除该选择集。否则可能导致程序出现意外。</p>
<p>&nbsp;</p>
<p>以下为修改后的部分代码,供参考:</p>
<p>&nbsp;</p>
<p><font face="Verdana">Sub uniteSS()</font></p>
<p><font face="Verdana">&nbsp; On Error Resume Next<br/>&nbsp; Dim ss As AcadSelectionSets<br/>&nbsp; Dim ssetObj As AcadSelectionSet<br/>&nbsp; <br/>&nbsp; If Not IsNull(ss.Item("uniteSS")) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set ssetObj = CreateSelectionSet("uniteSS")<br/>&nbsp;&nbsp;&nbsp;&nbsp; ssetObj.Delete<br/>&nbsp; End If<br/>&nbsp; <br/>&nbsp; Set ssetObj = CreateSelectionSet("uniteSS")<br/>&nbsp; Dim fType, fData<br/>&nbsp; BuildFilter fType, fData, -4, "&lt;or", 0, "line", 0, "LWPolyline", -4, "or&gt;"</font></p>
<p>&nbsp; ………………</p>
<p>&nbsp;</p>

xyz2009xyz 发表于 2010-8-12 19:58:00

<p>谢谢2楼,已经解决</p>
页: [1]
查看完整版本: [求助][讨论]这段连接线的代码为什么会出现如下的错误窗口