版主们,救命啊!
有如下代码用来删除指定区域内的块参照(Block Reference),可老是起不了作用啊!怎么办?救救我啊
Public Sub DelBlock()
建立选择集setp和setb,分别用来选择围成区域的3维多段线,和块参照<BR>Dim setb As AcadSelectionSet<BR>Dim setp As AcadSelectionSet<BR>Dim i As Integer<BR>Dim y As Integer<BR>Dim j As Integer<BR>Dim k As Integer
i = ThisDrawing.SelectionSets.Count
While (i)<BR>Set setb = ThisDrawing.SelectionSets.Item(i - 1)<BR>If setb.Name = "BlockR" Or setb.Name = "objlh" Then<BR> setb.Delete<BR>End If<BR>i = i - 1<BR>Wend
Set setb = ThisDrawing.SelectionSets.Add("BlockR")<BR>Set setp = ThisDrawing.SelectionSets.Add("objlh")
Dim gpcode(1) As Integer<BR>Dim datavalue(1) As Variant
gpcode(0) = 0<BR>datavalue(0) = "polyline"<BR>gpcode(1) = 8<BR>datavalue(1) = "Pathh"<BR>setp.Select acSelectionSetAll, , , gpcode, datavalue
获得4条3维多段线的4个交点
Dim obj1 As Acad3DPolyline<BR>Dim obj2 As Acad3DPolyline<BR>Dim pnt As Variant<BR>Dim pt(0 To 4, 0 To 2) As Variant
For k = 0 To 4<BR> For i = 0 To setp.Count - 1<BR> Set obj1 = setp.Item(i)<BR> For j = i + 1 To setp.Count - 1<BR> Set obj2 = setp.Item(j)<BR> pnt = obj1.IntersectWith(obj2, acExtendNone)<BR> If VarType(pnt) <> vbEmpty Then<BR> For y = LBound(pnt) To UBound(pnt)<BR> pt(k, y) = pnt(y)<BR> 'MsgBox "pt(" & k & "," & y & ")" & ":" & pt(k, y)<BR> Next y<BR> If k < 4 Then<BR> k = k + 1<BR> End If<BR> End If<BR> Next j<BR> Next i<BR>Next k
setp.Erase
'把得到的点组成pointList
Dim pts(0 To 11) As Double<BR>For i = 0 To 11<BR> For j = 1 To 4<BR> For k = 0 To 2<BR> pts(i) = pt(j, k)<BR> 'MsgBox pts(i)<BR> If i < 11 Then<BR> i = i + 1<BR> End If<BR> Next k<BR> Next j<BR>Next i
用以上点绘制三维多段线
Dim objline As Acad3DPolyline<BR>Set objline = ThisDrawing.ModelSpace.Add3DPoly(pts)
选择3维多段线的角点中的两个点
Dim endpoint1(0 To 2) As Double<BR>Dim endpoint2(0 To 2) As Double<BR>Dim coord1 As Variant<BR>Dim coord2 As Variant
coord1 = objline.Coordinate(0)<BR>coord2 = objline.Coordinate(3)
endpoint1(0) = coord1(0): endpoint1(1) = coord1(1): endpoint1(2) = coord1(2)<BR>endpoint2(0) = coord2(0): endpoint2(1) = coord2(1): endpoint2(2) = coord2(2)<BR>objline.Delete
<BR>gpcode(0) = 0
datavalue(0) = "insert"<BR><BR>setb.Select acSelectionSetAll, endpoint1, endpoint2, gpcode, datavalue<BR>MsgBox setb.Count
setb.Erase<BR> <BR> <BR>End Sub
这里声明一下:一直到获得两个点的地方却正确,可就是不能够选择块参照<BR> 选择块参照的时候要另外建一个过滤器,否则gpcode(1)和datavalue(1)依然有值,会只选择Pathh层的块参照 我现在新建了一个过滤器也还是没有用啊!
我把以下这写代码
gpcode(0) = 0
datavalue(0) = "insert"<BR><BR>setb.Select acSelectionSetAll, endpoint1, endpoint2, gpcode, datavalue<BR>MsgBox setb.Count
setb.Erase
改成<BR>
Dim fType(0 To 1) As Integer<BR> Dim fData(0 To 1) As Variant<BR> fType(0) = 0: fData(0) = "insert"<BR> fType(1) = 8: fData(1) = "ExtrudeFace,zz-1"<BR> <BR> setb.SelectByPolygon acSelectionSetCrossingPolygon, pts, fType, fData
MsgBox setb.Count
setb.Erase<BR>
可运行后还是提示setb的数量为0,块也并没有清除! 我已经按照楼上的说的,另外建了过滤器,代码如下:
Dim fType(0 To 1) As Integer<BR> Dim fData(0 To 1) As Variant<BR> fType(0) = 0: fData(0) = "insert"<BR> fType(1) = 8: fData(1) = "ExtrudeFace,zz-1"<BR> <BR> setb.SelectByPolygon acSelectionSetCrossingPolygon, pts, fType, fData
Msgbox setb.Count
setb.Erase
还是显示数量为0,且并没有清除任何块啊!<BR> 在前面加上
Application.ZoomExtents <A name=36608><FONT color=#990000><B>lzh741206</B></FONT></A>,我加了啊,还是不行!可不可以直接帮我调试一下看看啊!我现在再复制一份代码进来!
Public Sub DelBlock()<BR>Dim setb As AcadSelectionSet<BR>Dim setp As AcadSelectionSet<BR>Dim i As Integer<BR>Dim y As Integer<BR>Dim j As Integer<BR>Dim k As Integer
i = ThisDrawing.SelectionSets.Count
While (i)<BR>Set setb = ThisDrawing.SelectionSets.Item(i - 1)<BR>If setb.Name = "BlockR" Or setb.Name = "objlh" Then<BR> setb.Delete<BR>End If<BR>i = i - 1<BR>Wend
Set setb = ThisDrawing.SelectionSets.Add("BlockR")<BR>Set setp = ThisDrawing.SelectionSets.Add("objlh")
Dim gpcode(1) As Integer<BR>Dim datavalue(1) As Variant
gpcode(0) = 0<BR>datavalue(0) = "polyline"<BR>gpcode(1) = 8<BR>datavalue(1) = "Pathh"<BR>setp.Select acSelectionSetAll, , , gpcode, datavalue
Dim obj1 As Acad3DPolyline<BR>Dim obj2 As Acad3DPolyline<BR>Dim pnt As Variant<BR>Dim pt(0 To 4, 0 To 2) As Variant
For k = 0 To 4<BR> For i = 0 To setp.Count - 1<BR> Set obj1 = setp.Item(i)<BR> For j = i + 1 To setp.Count - 1<BR> Set obj2 = setp.Item(j)<BR> pnt = obj1.IntersectWith(obj2, acExtendNone)<BR> If VarType(pnt) <> vbEmpty Then<BR> For y = LBound(pnt) To UBound(pnt)<BR> pt(k, y) = pnt(y)<BR> 'MsgBox "pt(" & k & "," & y & ")" & ":" & pt(k, y)<BR> Next y<BR> If k < 4 Then<BR> k = k + 1<BR> End If<BR> End If<BR> Next j<BR> Next i<BR>Next k
setp.Erase
Dim pts(0 To 11) As Double<BR>For i = 0 To 11<BR> For j = 1 To 4<BR> For k = 0 To 2<BR> pts(i) = pt(j, k)<BR> 'MsgBox pts(i)<BR> If i < 11 Then<BR> i = i + 1<BR> End If<BR> Next k<BR> Next j<BR>Next i
Application.ZoomExtents
Dim fType(0 To 1) As Integer<BR>Dim fData(0 To 1) As Variant<BR>fType(0) = 0: fData(0) = "insert"<BR>fType(1) = 8: fData(1) = "ExtrudeFace,zz-1"<BR> <BR>setb.SelectByPolygon acSelectionSetCrossingPolygon, pts, fType, fData
MsgBox setb.Count
<BR>setb.Erase<BR> <BR> <BR>End Sub 和获得4条3维多段线的4个交点构成的顺序有关 lzh741206发表于2005-6-2 20:54:00static/image/common/back.gif在前面加上
Application.ZoomExtents
<BR>
我加了还是不行!
版主帮我看看啊?
Dim setb As AcadSelectionSet<BR>Dim setp As AcadSelectionSet<BR>Dim i As Integer<BR>Dim y As Integer<BR>Dim j As Integer<BR>Dim k As Integer
i = ThisDrawing.SelectionSets.Count
While (i)<BR>Set setb = ThisDrawing.SelectionSets.Item(i - 1)<BR>If setb.Name = "BlockR" Or setb.Name = "objlh" Then<BR> setb.Delete<BR>End If<BR>i = i - 1<BR>Wend
Set setb = ThisDrawing.SelectionSets.Add("BlockR")<BR>Set setp = ThisDrawing.SelectionSets.Add("objlh")
Dim gpcode(1) As Integer<BR>Dim datavalue(1) As Variant
gpcode(0) = 0<BR>datavalue(0) = "polyline"<BR>gpcode(1) = 8<BR>datavalue(1) = "Pathh"<BR>setp.Select acSelectionSetAll, , , gpcode, datavalue
Dim obj1 As Acad3DPolyline<BR>Dim obj2 As Acad3DPolyline<BR>Dim pnt As Variant<BR>Dim pt(0 To 4, 0 To 2) As Variant
For k = 0 To 4<BR> For i = 0 To setp.Count - 1<BR> Set obj1 = setp.Item(i)<BR> For j = i + 1 To setp.Count - 1<BR> Set obj2 = setp.Item(j)<BR> pnt = obj1.IntersectWith(obj2, acExtendNone)<BR> If VarType(pnt) <> vbEmpty Then<BR> For y = LBound(pnt) To UBound(pnt)<BR> pt(k, y) = pnt(y)<BR> 'MsgBox "pt(" & k & "," & y & ")" & ":" & pt(k, y)<BR> Next y<BR> If k < 4 Then<BR> k = k + 1<BR> End If<BR> End If<BR> Next j<BR> Next i<BR>Next k
setp.Erase
Dim pts(0 To 11) As Double<BR>For i = 0 To 11<BR> For j = 1 To 4<BR> For k = 0 To 2<BR> pts(i) = pt(j, k)<BR> 'MsgBox pts(i)<BR> If i < 11 Then<BR> i = i + 1<BR> End If<BR> Next k<BR> Next j<BR>Next i
Application.ZoomExtents
Dim fType(0 To 1) As Integer<BR>Dim fData(0 To 1) As Variant<BR>fType(0) = 0: fData(0) = "insert"<BR>fType(1) = 8: fData(1) = "ExtrudeFace,zz-1"<BR> <BR>setb.SelectByPolygon acSelectionSetCrossingPolygon, pts, fType, fData
MsgBox setb.Count
<BR>setb.Erase<BR> <BR> <BR>End Sub<BR> lzh741206发表于2005-6-3 9:51:00static/image/common/back.gif和获得4条3维多段线的4个交点构成的顺序有关
我把点的顺序也更改了,但还是不行!帮忙看看吧!
<BR>Public Sub DelBlock()<BR>Dim setb As AcadSelectionSet<BR>Dim setp As AcadSelectionSet<BR>Dim i As Integer<BR>Dim y As Integer<BR>Dim j As Integer<BR>Dim k As Integer
i = ThisDrawing.SelectionSets.Count
While (i)<BR>Set setb = ThisDrawing.SelectionSets.Item(i - 1)<BR>If setb.Name = "BlockR" Or setb.Name = "objlh" Then<BR> setb.Delete<BR>End If<BR>i = i - 1<BR>Wend
Set setb = ThisDrawing.SelectionSets.Add("BlockR")<BR>Set setp = ThisDrawing.SelectionSets.Add("objlh")
Dim gpcode(1) As Integer<BR>Dim datavalue(1) As Variant
gpcode(0) = 0<BR>datavalue(0) = "polyline"<BR>gpcode(1) = 8<BR>datavalue(1) = "Pathh"<BR>setp.Select acSelectionSetAll, , , gpcode, datavalue
Dim obj1 As Acad3DPolyline<BR>Dim obj2 As Acad3DPolyline<BR>Dim pnt As Variant<BR>Dim pt(0 To 4, 0 To 2) As Variant
For k = 0 To 4<BR> For i = 0 To setp.Count - 1<BR> Set obj1 = setp.Item(i)<BR> For j = i + 1 To setp.Count - 1<BR> Set obj2 = setp.Item(j)<BR> pnt = obj1.IntersectWith(obj2, acExtendNone)<BR> If VarType(pnt) <> vbEmpty Then<BR> For y = LBound(pnt) To UBound(pnt)<BR> pt(k, y) = pnt(y)<BR> 'MsgBox "pt(" & k & "," & y & ")" & ":" & pt(k, y)<BR> Next y<BR> If k < 4 Then<BR> k = k + 1<BR> End If<BR> End If<BR> Next j<BR> Next i<BR>Next k
setp.Erase
Dim pts(0 To 11) As Double<BR>For i = 0 To 11<BR> For j = 1 To 4<BR> For k = 0 To 2<BR> pts(i) = pt(j, k)<BR> If i < 11 Then<BR> i = i + 1<BR> End If<BR> Next k<BR> Next j<BR>Next i
Dim tp(0 To 3) As Double<BR>For i = 9 To 11<BR>tp(i - 9) = pts(i)<BR>pts(i) = pts(i - 3)<BR>pts(i - 3) = tp(i - 9)<BR>Next i
<BR>For i = 0 To 11<BR>MsgBox pts(i)<BR>Next i
<BR>Application.ZoomExtents
Dim fType(0 To 1) As Integer<BR>Dim fData(0 To 1) As Variant<BR>fType(0) = 0: fData(0) = "insert"<BR>fType(1) = 8: fData(1) = "ExtrudeFace,zz-1"<BR> <BR>setb.SelectByPolygon acSelectionSetCrossingPolygon, pts, fType, fData
MsgBox setb.Count
<BR>setb.Erase<BR> <BR> <BR>End Sub 你的树和路灯的z轴坐标最少为30,你用一根z轴坐标为0的多段线的intersectwith方法就根本得不到任何的交点。
页:
[1]
2