egua 发表于 2007-1-9 13:34:00

如何实现关闭已选择实体的图层??

<p>想编一个程序:</p><p>输入命令,从屏幕选择实体,程序判断已选实体的图层,然后将其关闭!</p><p>判高手指点一下~</p>

wyj7485 发表于 2007-1-9 13:45:00

Sub test()
Dim Obj As Object
Dim PickP As Variant
ThisDrawing.Utility.GetEntity Obj, PickP, "选择要关闭该层的图元:"
ThisDrawing.Layers.Item(Obj.Layer).LayerOn = False
End Sub

egua 发表于 2007-1-9 14:02:00

<p>多谢啦</p><p>还想问问如果用选择集的方法可以么?</p><p>同时实现cad的框选功能,并且像输入cad命令一样,敲选回车后才关闭图层~</p>

wyj7485 发表于 2007-1-9 14:07:00

选择集当然可以,只是选择集里的实体不一定都在一个层上,这样就要遍历选择集来处理

egua 发表于 2007-1-9 15:04:00

多谢斑竹,我写了如下代码:看看有什么问题哦
Sub test()
Dim ssetobj As AcadSelectionSet
Dim s As AcadSelectionSet
On Error Resume Next
   Set ssetobj = ThisDrawing.SelectionSets.Add("egua")
   If Err Then
         Err.Clear
         Set ssetobj = ThisDrawing.SelectionSets.Item("egua")
   End If
   ssetobj.Clear

ssetobj.SelectOnScreen
For Each s In ssetobj
ThisDrawing.Layers.Item(s.Layer).LayerOn = False
Next s
End Sub

afeng11 发表于 2011-11-3 14:58:42

Sub test()
Dim ssetobj As AcadSelectionSet
Dim s As AcadSelectionSet这里有问题,要改成这样:Dim s As AcadEntity
On Error Resume Next
   Set ssetobj = ThisDrawing.SelectionSets.Add("egua")
   If Err Then
         Err.Clear
         Set ssetobj = ThisDrawing.SelectionSets.Item("egua")
   End If
   ssetobj.Clear

ssetobj.SelectOnScreen
For Each s In ssetobj
   ThisDrawing.Layers.Item(s.Layer).LayerOn = False
Next s
End Sub

sousence 发表于 2012-6-29 22:22:35

页: [1]
查看完整版本: 如何实现关闭已选择实体的图层??