kdst 发表于 2009-8-9 22:19:00

[求助]VBA这样的选择集怎样写

<p>直线的起点坐标为10,25,终点的坐标为100,129,图层名为LINE1,画图之前现要判断这条线是否存在,如果存在且图层相同,则不画这条线,如果不存在或存在但图层不是LINE1就画这条线,在直线的两端分别插入两个名称为2的块,图层名为BLOCK1,再在直线两端分别插入两个单行文字“起点”“终点”,画图之前现要判断他们是否存在,块和文字同样要做与直线相同的判断。有那位大哥知道改怎么写吗?</p>

雪山飞狐_lzh 发表于 2009-8-10 00:46:00

<p>过滤器:pnt1,pnt2先赋值</p><p>0,"line",</p><p>10,pnt1,</p><p>10,pnt2,</p><p>8,"line1"</p>

kdst 发表于 2009-8-10 03:27:00

<p>我这样写怎么不行,而且直线都画不出来,问题出在哪里?</p><p>Sub lline()</p><p><br/>Dim linex As AcadLine<br/>Dim pnt1(2) As Double, pnt2(2) As Double<br/>pnt1(0) = 10:&nbsp; pnt1(1) = 25:&nbsp; pnt1(2) = 0<br/>pnt2(0) = 100: pnt2(1) = 129: pnt2(2) = 0</p><p>Dim sset As AcadSelectionSet<br/>Set sset = ThisDrawing.SelectionSets.Add("temline")</p><p>Dim FilterType As Variant, FilterData As Variant<br/>Dim gpCode(3) As Integer, dataValue(3) As Variant</p><p><br/>gpCode(0) = 0<br/>dataValue(0) = "LINE"</p><p><br/>gpCode(1) = 8<br/>dataValue(1) = "LINE1"</p><p><br/>gpCode(2) = 10<br/>dataValue(2) = pnt1</p><p><br/>gpCode(3) = 10<br/>dataValue(3) = pnt2</p><p><br/>FilterType = gpCode<br/>FilterData = dataValue</p><p><br/>sset.Select acSelectionSetAll, FlterType, FilterData</p><p>If sset.Count = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set linex = ThisDrawing.ModelSpace.AddLine(pt1, pt2)<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "该线段已存在"<br/>&nbsp;&nbsp;&nbsp; End If</p><p>End Sub</p>

雪山飞狐_lzh 发表于 2009-8-10 08:34:00

<p>搞错:),终点DXF码是11</p><p></p><p>Sub test()<br/>On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; Dim sset As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets("temline").Delete<br/>&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Add("temline")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim pnt1(2) As Double, pnt2(2) As Double<br/>&nbsp;&nbsp;&nbsp; pnt1(0) = 10:&nbsp; pnt1(1) = 25:&nbsp; pnt1(2) = 0<br/>&nbsp;&nbsp;&nbsp; pnt2(0) = 100: pnt2(1) = 129: pnt2(2) = 0<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim ft(3) As Integer, fd(3) As Variant<br/>&nbsp;&nbsp;&nbsp; ft(0) = 0: fd(0) = "LINE"<br/>&nbsp;&nbsp;&nbsp; ft(1) = 8: fd(1) = "LINE1"<br/>&nbsp;&nbsp;&nbsp; ft(2) = 10: fd(2) = pnt1<br/>&nbsp;&nbsp;&nbsp; ft(3) = 11: fd(3) = pnt2<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; sset.Select acSelectionSetAll, , , ft, fd<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim linex As AcadLine<br/>&nbsp;&nbsp;&nbsp; If sset.Count = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set linex = ThisDrawing.ModelSpace.AddLine(pnt1, pnt2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linex.Layer = "LINE1"<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "该线段已存在"<br/>&nbsp;&nbsp;&nbsp; End If<br/>End Sub<br/></p>

kdst 发表于 2009-8-10 22:19:00

原来是这样,谢谢指点!
页: [1]
查看完整版本: [求助]VBA这样的选择集怎样写