使用场景:参照冻结、图块冻结,模型/视口内都可
近期因为图层冻结的事情困扰,只学过一点python,只能百度搜索加上论坛上查阅了好多资料,终于捣鼓出来了一点,个人觉得还不是很完美(ps:点击图块/参照内容的时候需要二次点击确认下)咱先把源码贡献出来,也请大牛看看能不能进一步优化以提升使用体验!
- (defun c:k ()
- (if (/= (getvar "clayer") 0) ;判断当前图层是否为0图层
- (vl-cmdf "-LAYER" "S" 0 ""))
- (setq dh_kj(getvar "ctab")) ;获取当前所在空间是模型/布局
- (if(/= dh_kj "Model") ;如果当前不是在模型空间,是在布局内
- (while
- (setq Ent(entsel "\n选择对象:"));获取实体(块或者线)
- (setq Ent1(cdr (assoc 0 (entget (car Ent)))))
- (setq Ent_lay (cdr (assoc 8 (entget (car Ent)))));获取实体(块或者线)的图层名
- (if (= Ent1 "INSERT")
- (progn
- (setq ss1 (nentsel "\n选择的是块,需要再点击一次: ")) ;获取实体(线)
- (setq Ltp (cdr (assoc 8 (entget (car ss1)))));获取实体(线)的图层名
- (if (= Ltp "0")
- (if(= Ltp Ent_lay)
- (progn
- (print "您选择的图块及图元都是")
- (princ Ent_lay)
- (prompt "图层,请检查!")
- )
- (progn
- (command "vplayer" "F" Ent_lay "C" "")
- (print "图层 ")
- (princ Ent_lay)
- (prompt " 已冻结")
- )
- )
- (progn
- (command "vplayer" "F" Ltp "C" "")
- (print "图层 ")
- (princ Ltp)
- (prompt " 已冻结")
- )
- )
- )
- (vl-cmdf "LAYFRZ" "S" "v" "v" Ent "") ;冻结所选对象图层
- )
- )
- (while
- (setq Ent(entsel "\n选择对象:"));获取实体(块或者线)
- (setq Ent1(cdr (assoc 0 (entget (car Ent)))))
- (setq Ent_lay (cdr (assoc 8 (entget (car Ent)))));获取实体(块或者线)的图层名
- (if (= Ent1 "INSERT")
- (progn
- (setq ss1 (nentsel "\n选择的是块,需要再点击一次: ")) ;获取实体(线)
- (setq Ltp (cdr (assoc 8 (entget (car ss1)))));获取实体(线)的图层名
- (if (= Ltp "0")
- (if(= Ltp Ent_lay)
- (progn
- (print "您选择的图块及图元都是")
- (princ Ent_lay)
- (prompt "图层,请检查!")
- )
- (progn
- (command "_layer" "F" Ent_lay "")
- (print "图层 ")
- (princ Ent_lay)
- (prompt " 已冻结")
- )
- )
- (progn
- (command "_layer" "F" Ltp "")
- (print "图层 ")
- (princ Ltp)
- (prompt " 已冻结")
- )
- )
- )
- (vl-cmdf "LAYFRZ" "S" "B" "B" Ent "") ;冻结所选对象图层
- )
- )
- )
- )
|