找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 483|回复: 1

[必看]:恭喜新版主上任,送点见面礼

[复制链接]
发表于 2004-6-2 20:14:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
首先恭喜新斑竹上任,送上份贺礼!!

以后还会有更多更精彩的内容奉献给大家。



声明:本帖内容禁止转贴,请注意!!![/COLOR][/SIZE]

  1. use VBA events to keep a layer from being unlocked  
  2. ID    83365  
  3. Applies to:    AutoCAD 2002
  4. AutoCAD 2004

  5. Date    1/30/2004  

  6. This document is part of   Layers   VBA   


  7. Question
  8. Is there a way to keep a layer locked using VBA events?
  9. Answer
  10. Four different events could be used to keep a layer locked. Below is a VBA example
  11. that keeps a layer named "Layer1" locked. The EndCommand locks Layer1 if the
  12. layer command was run. The ObjectModified changes a global flag to true when
  13. the Toolbar is used to unlock the layer. When a command is started the BeginCommand
  14. checks this flag and locks the layer. The SelectionChanged event checks this
  15. flag and locks the layer when an entity is selected.

  16. To test this example copy this code into the ThisDrawing module in the VBA editor


  17. Public checkLayer As Boolean

  18. Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
  19.     If CommandName = "LAYER" Or CommandName = "-LAYER" Then
  20.         Dim ly As AcadLayer
  21.         For Each ly In ThisDrawing.Layers
  22.             If ly.Name = "Layer1" Then
  23.                 ly.Lock = True
  24.             End If
  25.         Next ly
  26.    End If
  27. End Sub

  28. Private Sub AcadDocument_ObjectModified(ByVal Object As Object)
  29.     If Object.ObjectName = "AcDbLayerTableRecord" Then
  30.         If Object.Name = "Layer1" Then
  31.             checkLayer = True
  32.         End If
  33.     End If

  34. End Sub

  35. Private Sub AcadDocument_SelectionChanged()
  36.     If checkLayer = True Then
  37.         ThisDrawing.Layers("Layer1").Lock = True
  38.         checkLayer = False
  39.     End If
  40. End Sub

  41. Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
  42.     If checkLayer = True Then
  43.         ThisDrawing.Layers("Layer1").Lock = True
  44.         checkLayer = False
  45.     End If
  46. End Sub


声明:本帖内容禁止转贴,请注意!!![/COLOR][/SIZE]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2004-6-3 18:24:34 | 显示全部楼层
谢谢捧场,期待你的精彩内容,如果有好的我会考虑封红包的
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-29 09:24 , Processed in 0.348071 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表