马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CP原创]VBA/VLISP函数:设置当前层双解对照
- '
- '设置当前层,如果指定名称的层不存在则新建
- '
- Public Function myvb_LayerSet(LayerName As String)
-
- Dim objLayer As AcadLayer
- Dim FindLayer As Boolean
-
- FindLayer = False
- For Each objLayer In ThisDrawing.Layers
- If UCase(objLayer.Name) = UCase(LayerName) Then
- FindLayer = True
- Exit For
- End If
- Next
-
- If FindLayer = True Then '已存在
- Set objLayer = ThisDrawing.Layers(LayerName)
- If objLayer.Freeze = True Then '解冻
- objLayer.Freeze = False
- End If
- objLayer.Lock = False '解锁
- objLayer.LayerOn = True '可见
- Else '不存在时新建
- Set objLayer = ThisDrawing.Layers.Add(LayerName)
- End If
- ThisDrawing.ActiveLayer = objLayer '设为当前层
- End Function
- ;;;======================================================================;
- ;;;设置当前层,如果指定名称的层不存在则新建 ;
- ;;;======================================================================;
- (defun myvl_LayerSet (layName / acDoc lays lay)
- (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object))
- lays (vla-get-Layers acDoc)
- )
- (if (= (tblsearch "layer" layName) nil)
- (progn ;不存在
- (setq lay (vla-Add lays layName)) ;新建
- (vla-put-ActiveLayer acDoc lay) ;设为当前层
- )
- (progn ;已存在
- (setq lay (vla-Item lays layName))
- (if (= (vla-get-Freeze lay) :vlax-true)
- (vla-put-Freeze lay :vlax-false) ;解冻
- )
- (if (= (vla-get-Lock lay) :vlax-true)
- (vla-put-Lock lay :vlax-false) ;解锁
- )
- (if (= (vla-get-LayerOn lay) :vlax-false)
- (vla-put-LayerOn lay :vlax-true) ;可见
- )
- (vla-put-ActiveLayer acDoc lay) ;设为当前层
- )
- )
- )
|