当前版块:问答社区 > CASS

[CASS二次开发源代码]VB6+AutoCAD---图层控制

Windows10
其他
CASS9
Public Sub ILayerOn(ByVal AcadApp As Object) '图层全开
  Dim objLyr As Object
  For Each objLyr In AcadApp.Application.ActiveDocument.Layers
      objLyr.LayerOn = True
  Next
End Sub
Public Sub ILayerOff(ByVal AcadApp As Object) '图层选关
  Dim objLyr As Object, objEnt As Object, sSet As Object
  For Each sSet In AcadApp.Application.ActiveDocument.SelectionSets
      If sSet.Name = "ILayerOff" Then sSet.Delete: Exit For
  Next
  Set sSet = AcadApp.Application.ActiveDocument.SelectionSets.Add("ILayerOff")
  sSet.SelectOnScreen
  If sSet.Count > 0 Then
     For Each objEnt In sSet
         For Each objLyr In AcadApp.Application.ActiveDocument.Layers
             If objLyr.Name = objEnt.Layer Then
                objLyr.LayerOn = False
             End If
         Next
     Next
  End If
  sSet.Delete
End Sub
Public Sub ILayerOffExcept(ByVal AcadApp As Object) '图层指定外关闭
  Dim objLyr As Object, objEnt As Object, sSet As Object
  For Each sSet In AcadApp.Application.ActiveDocument.SelectionSets
      If sSet.Name = "ILayerOffExcept" Then sSet.Delete: Exit For
  Next
  Set sSet = AcadApp.Application.ActiveDocument.SelectionSets.Add("ILayerOffExcept")
  sSet.SelectOnScreen
  If sSet.Count > 0 Then
     For Each objEnt In sSet
         For Each objLyr In AcadApp.Application.ActiveDocument.Layers
             If objLyr.Name <> objEnt.Layer Then
                objLyr.LayerOn = False
             End If
         Next
     Next
  End If
  sSet.Delete
End Sub
Public Sub ILayerLock(ByVal AcadApp As Object) '图层锁定
  Dim objLyr As Object, objEnt As Object, sSet As Object
  For Each sSet In AcadApp.Application.ActiveDocument.SelectionSets
      If sSet.Name = "ILayerLock" Then sSet.Delete: Exit For
  Next
  Set sSet = AcadApp.Application.ActiveDocument.SelectionSets.Add("ILayerLock")
  sSet.SelectOnScreen
  If sSet.Count > 0 Then
     For Each objEnt In sSet
         For Each objLyr In AcadApp.Application.ActiveDocument.Layers
             If objLyr.Name = objEnt.Layer Then
                objLyr.Lock = True
             End If
         Next
     Next
  End If
  sSet.Delete
End Sub
Public Sub ILayerUnlock(ByVal AcadApp As Object) '图层开锁
  Dim objLyr As Object
  For Each objLyr In AcadApp.Application.ActiveDocument.Layers
      objLyr.Lock = False
  Next
End Sub
Public Sub ILayerFreeze(ByVal AcadApp As Object)    '图层冻结
  Dim objEnt As Object, objLyr As Object, pnt As Variant, sSet As Object
  For Each sSet In AcadApp.Application.ActiveDocument.SelectionSets
      If sSet.Name = "ILayerFreeze" Then sSet.Delete: Exit For
  Next
  Set sSet = AcadApp.Application.ActiveDocument.SelectionSets.Add("ILayerFreeze")
  sSet.SelectOnScreen
  If sSet.Count > 0 Then
     For Each objEnt In sSet
         For Each objLyr In AcadApp.Application.ActiveDocument.Layers
             If objLyr.Name = objEnt.Layer Then
                If AcadApp.Application.ActiveDocument.ActiveLayer.Name <> objLyr.Name Then
                   objLyr.Freeze = True
                End If
             End If
         Next
     Next
  End If
  sSet.Delete
End Sub
Public Sub ILayerUnfreeze(ByVal AcadApp As Object)     '图层解冻
  Dim objLyr As Object
  For Each objLyr In AcadApp.Application.ActiveDocument.Layers
      If objLyr.Freeze = True Then objLyr.Freeze = False
  Next
  AcadApp.Application.ActiveDocument.Regen acActiveViewport
End Sub
Public Sub ILayerCur(ByVal AcadApp As Object)   '图层当前
  Dim objEnt As Object, objLyr As Object, pnt As Variant
  On Error Resume Next
  AcadApp.Application.ActiveDocument.Utility.GetEntity objEnt, pnt, vbCr & vbCr & "选择对象:"
  If Err Then Err.Clear: Exit Sub
  Set objLyr = AcadApp.Application.ActiveDocument.Layers(objEnt.Layer)
  AcadApp.Application.ActiveDocument.ActiveLayer = objLyr
End Sub

全部评论

等级:LV30
积分:74546
hkai2658 2019-12-11 08:35
没有看懂
回复 0
1
提交
悬赏回复规则
1、悬赏期为24小时,从发布时间起算;
2、悬赏期内提问者如设置评论为“精选评论”,视为悬赏结束,该精选评论人将获得本题全部悬赏积分;
3、悬赏期内如提问者未设置“精选评论”,则前5位评论者平分悬赏积分(如仅有一位评论,该评论者获得50%悬赏积分);
4、悬赏积分会自动发放到生态圈账户中,请留意站内信通知。
知道了

距离打开宝箱还剩7

是否花费200积分补签?
确认
取消