[VBA]VBA精彩实例教程删除实体所在图层问题
<DIV>以下过程转贴自<<AutoCAD VBA精彩实例教程>>,实际运行中会发生同时删除多个实体的现象,不知何故?</DIV><DIV>Sub cmdDel()<BR> ' 删除实体所在图层<BR> On Error Resume Next<BR> Dim objdest As AcadEntity<BR> Dim ptBase As Variant<BR> ThisDrawing.Utility.GetEntity objdest, ptBase, "选择所在层实体>>"<BR> Dim objent As AcadEntity<BR> For Each objent In ThisDrawing.ModelSpace<BR> If objent.Layer = objdest.Layer Then<BR> objent.Delete<BR> End If<BR> Next<BR> Dim objLayer As AcadLayer<BR> Set objLayer = ThisDrawing.Layers.Item(objdest.Layer)<BR> objLayer.Delete<BR>End Sub</DIV> 你要达到什么效果? <P>Sub tcDel() '删除实体所在图层<BR> On Error Resume Next<BR> '删除图层中的对象<BR> Dim objDest As AcadEntity<BR> Dim ptBase As Variant<BR> Dim FilterType As Variant<BR> Dim FilterData As Variant<BR> Dim Sel As AcadSelectionSet<BR> Dim Fdata(0) As Variant<BR> Dim Ftype(0) As Integer<BR> Dim Pickedobj As AcadEntity<BR> Dim VByn As String<BR> Dim TcName As String<BR> Do<BR> ThisDrawing.Utility.GetEntity objDest, ptBase, "选择所删除图层中的实体>>"<BR> If objDest.ObjectName = "" Then<BR> VByn = MsgBox("请重新选择图层", 5, "删除图层")<BR> If VByn <> "4" Then<BR> Exit Sub<BR> End If<BR> Else<BR> Exit Do<BR> End If<BR> Loop<BR> Ftype(0) = 8<BR> Fdata(0) = objDest.Layer<BR> FilterType = Ftype<BR> FilterData = Fdata<BR> TcName = objDest.Layer<BR> If ThisDrawing.Layers(TcName).Lock = True Then<BR> VByn = MsgBox("该图层已锁定,删除", 4, "删除图层")<BR> If VByn = "6" Then<BR> ThisDrawing.Layers(TcName).Lock = False '解锁<BR> Else<BR> Exit Sub<BR> End If<BR> End If<BR> Set Sel = ThisDrawing.SelectionSets.Add("ssel")<BR> If Err Then<BR> Err.Clear<BR> ThisDrawing.SelectionSets("ssel").Delete<BR> Set Sel = ThisDrawing.SelectionSets.Add("ssel")<BR> End If<BR> Sel.Select acSelectionSetAll, , , FilterType, FilterData<BR> For Each Pickedobj In Sel<BR> Pickedobj.Delete<BR> Next<BR>End Sub</P>
<P> </P> lzh741206发表于2005-11-29 8:14:00static/image/common/back.gif你要达到什么效果?
<DIV>选那一层删除那一层.</DIV>
<DIV>但以上例子有时除了删除所选的那一层外,还会附带将别的层(别的一层或多层)也删除了.<BR></DIV>
页:
[1]