大侠,有空看看毛病在那儿,谢谢。
(defun c:tmp(/ typ )(initget 1 "S F T")
(setq typ (getkword "\n 关闭部分F、全部打开T、显示部分S:"))
(cond ((= typ "F") (f_lay))
((= typ "T") (command "-layer" "on" "*"""))
((= typ "S") (s_lay))
)
)
;关闭图层
(defun f_lay(/ ss i ssn lay)
(princ "\n选择图层参考块:")
(setq ss (ssget))
(setq i 0)
;(command "layer")
(repeat (sslength ss)
(setq ssn (ssname ss i ))
(setq lay (cdr (assoc 8 (entget ssn))))
(command "-layer" "off" lay"" )
(setq i ( + i 1))
)
(command "")
)
;保留图层
(defun s_lay(/ ss i ssn lay)
(princ "\n选择图层参考块:")
(setq ss (ssget))
(command "-layer" "off" "*""")
(setq i 0 )
(repeat(sslength ss)
(setq ssn (ssname ss i ))
(setq lay (cdr ( assoc 8 (entget ssn))))
(command "-layer""on" lay "")
(setq i ( + i 1))
)
;(command "")
)
(princ "\n程序加载完成")
(princ "\n")
本帖最后由 xyp1964 于 2024-2-1 19:43 编辑
(defun Ukword (bit kwd msg def / inp)
(if (and def (/= def ""))
(setq msg (strcat "\n" msg "<" def ">: ")
bit (* 2 (fix (/ bit 2)))
)
(setq msg (strcat "\n" msg ": "))
)
(initget bit kwd)
(setq inp (getkword msg))
(if inp
inp
def
)
)
(defun c:tt ()
(or kw(setq kw "1"))
(setq kw (Ukword 1 "1 2 3""[关闭部分(1)/全部打开(2)/显示部分(3)/]" kw))
(cond((= kw "1") (f_lay))
((= kw "2") (command "-layer" "on" "*" ""))
((= kw "3") (s_lay))
)
(princ)
)
;; 关闭图层
(defun f_lay ()
(princ "\n选择图层参考块: ")
(setq i -1)
(if (setq ss (ssget))
(progn
(while (setq s1 (ssname ss (setq i (1+ i))))
(setq la (cdr (assoc 8 (entget s1))))
(command "-layer" "off" la "")
)
)
)
)
;; 保留图层
(defun s_lay ()
(princ "\n选择图层参考块: ")
(if (setq ss (ssget))
(progn
(command "-layer" "off" "*" "")
(setq i -1)
(while (setq s1 (ssname ss (setq i (1+ i))))
(setq la (cdr (assoc 8 (entget s1))))
(command "-layer" "on" la "")
)
)
)
)
(princ)
本帖最后由 wide 于 2024-2-1 18:28 编辑
{:1_1:}{:1_1:}{:1_1:}{:1_1:} ;现在这码能跑了,哈哈
(defun c:tmp(/ typ )
(initget 1 "S F T")
(setq typ (getkword "\n 关闭部分F、全部打开T、显示部分S:"))
(cond ((= typ "F") (f_lay))
((= typ "T") (command "-layer" "on" "*"""))
((= typ "S") (s_lay))
)
)
;关闭图层
(defun f_lay(/ ss i ssn lay)
(princ "\n选择图层参考块:")
(setq ss (ssget))
(setq i 0)
;(command "layer")
(repeat (sslength ss)
(setq ssn (ssname ss i ))
(setq lay (cdr (assoc 8 (entget ssn))))
(command "-layer" "off" lay"" )
(setq i ( + i 1))
)
(command "")
)
;保留图层
(defun s_lay(/ ss i ssn lay)
(princ "\n选择图层参考块:")
(setq ss (ssget))
(command "layer" "off" "*" "y" "")
(setq i 0 )
(repeat(sslength ss)
(setq ssn (ssname ss i ))
(setq lay (cdr ( assoc 8 (entget ssn))))
(command "layer" "on" lay "")
(setq i ( + i 1))
)
;(command "")
)
(princ "\n程序加载完成")
(princ "\n")
留个脚印,挺好用 (defun Ukword (bit kwd msg def / inp)
; 定义函数 Ukword,用于获取用户输入的关键字
(if (and def (/= def ""))
; 如果提供了默认值 def 且不为空字符串
(setq msg (strcat "\n" msg "<" def ">: ")
bit (* 2 (fix (/ bit 2))))
; 构建提示消息,包含默认值
(setq msg (strcat "\n" msg ": ")))
; 构建提示消息,不包含默认值
(initget bit kwd)
; 使用 initget 函数设置关键字输入的选项
(setq inp (getkword msg))
; 使用 getkword 函数获取用户输入的关键字
(if inp
inp
def))
(defun c:ttt ()
; 定义命令函数 c:ttt
(or kw (setq kw "1"))
; 如果变量 kw 未定义,则将其设置为默认值 "1"
(setq kw (Ukword 1 "1 2 3 4" "[关闭部分(1)/全部打开(2)/显示部分(3)/上一次图层(4)/]" kw))
; 使用 Ukword 函数获取用户输入的关键字,提供选项和相应的提示消息
(cond
((= kw "1") (f_lay))
; 如果关键字为 "1",调用函数 f_lay
((= kw "2") (command "-layer" "on" "*" ""))
; 如果关键字为 "2",执行打开所有图层的命令
((= kw "3") (s_lay))
; 如果关键字为 "3",调用函数 s_lay
((= kw "4") (command "_LayerP")))
; 如果关键字为 "4",执行上一次图层的命令
(princ))
; 返回空值
; 关闭图层
(defun f_lay (/ ss c en lay)
; 定义函数 f_lay,用于关闭图层
(princ "\n选择图层参考块:")
; 提示用户选择图层参考块
(setq ss (ssget))
; 获取用户选择的图层参考块
(setq c 0)
; 初始化计数器 c
(while (< c (sslength ss))
; 循环处理每个图层参考块
(setq en (ssname ss c))
; 获取图层参考块的名字
(setq lay (cdr (assoc 8 (entget en))))
; 获取图层参考块的图层名
(if (not (member lay laylst))
; 如果图层名不在 laylst 列表中,则将其添加到列表中
(setq laylst (cons lay laylst)))
(if (= lay (getvar "clayer"))
; 如果图层名与当前图层相同,则关闭图层并保留对象
(command "-layer" "off" lay "y" "")
(command "-layer" "off" lay ""))
; 否则,关闭图层
(setq c (1+ c)))
; 增加计数器 c
(princ))
; 返回空值
; 保留图层
(defun s_lay (/ Es ES EN EL A ss)
; 定义函数 s_lay,用于保留图层
(princ "\n选择图层参考块:")
; 提示用户选择图层参考块
(setq ss (ssget))
; 获取用户选择的图层参考块
(setq A 0 EN "" EL nil FL nil)
; 初始化变量 A、EN、EL、FL
(while (/= EN nil)
; 循环处理每个图层参考块
(setq EN (ssname ss A) EL (cons EN EL) A (1+ A)))
; 获取图层参考块的名字,并增加计数器 A
(setq EL (cdr EL) FL (cdr (assoc ' 8 (entget (car EL)))) EL (cdr EL)
ss (ssget "_X" (list (cons 0 "INSERT"))))
; 获取图层参考块的图层名,并筛选出插入的图块
(repeat (- A 2)
; 循环处理每个图层参考块的图层名
(setq EN (cdr (assoc ' 8 (entget (car EL))))
FL (strcat EN "," FL) EL (cdr EL)))
; 将图层名添加到 FL 变量中,并更新 EL 变量
(command "LAYER" "off" "*" "y" "on" (eval FL) "")
; 关闭指定图层
(princ)
; 返回空值
)
(princ "\n命令:TTT 图层管理:关闭部分(1)/全部打开(2)/显示部分(3)/上一次图层(4)")
(princ)
不错不错 moshouhot 发表于 2024-2-2 22:35
不错不错
能否改为布局中的视口冻结、解冻,这样布局就更方便了。
页:
[1]