请改写一个autocad一次关闭多个图层的autolisp函数吧!
函数如下:;;;2.2LayerOffM关闭物体所在的层(多选)(DefunC:LayerOffM()(setvar"cmdecho"0)(prompt"\nSelect...
函数如下:
;;; 2.2 LayerOffM 关闭物体所在的层(多选)
(Defun C:LayerOffM ()
(setvar "cmdecho" 0)
(prompt "\nSelect entities to turn off:")
(setq ss (ssget))
(if (and
ss
(sslength ss)
0
)
(progn
(setq ct 0
len (sslength ss)
cl (getvar "clayer")
)
(command ".layer")
(while (< ct len)
(setq la (cdr (assoc 8 (entget (ssname ss ct)))))
(if (/= cl la)
(command "off" la)
(progn
(prompt "\nThe layer")
(prompt la)
(prompt "is CURRENT!")
)
)
(if (= old nil)
(setq OLD la)
(setq OLD (strcat OLD "," la))
)
(setq ct (1+ ct))
)
(command "")
)
)
(princ)
(setvar "cmdecho" 0)
(prin1)
)
这个函数有一个问题,如果选择的图层包含了当前图层,就不能关闭
当前图层。
我想把它修改一下:如果当前选择的多个图层中包含了当前图层,
那么给用户一个是否关闭当前图层的选择,如果用户选择了y,则
关闭当前图层,如果用户选择了n,则不关闭当前图层。
谢谢了,就这么多!
如果可以的话,请帮忙注释一下这个程序!
谢谢了! 展开
;;; 2.2 LayerOffM 关闭物体所在的层(多选)
(Defun C:LayerOffM ()
(setvar "cmdecho" 0)
(prompt "\nSelect entities to turn off:")
(setq ss (ssget))
(if (and
ss
(sslength ss)
0
)
(progn
(setq ct 0
len (sslength ss)
cl (getvar "clayer")
)
(command ".layer")
(while (< ct len)
(setq la (cdr (assoc 8 (entget (ssname ss ct)))))
(if (/= cl la)
(command "off" la)
(progn
(prompt "\nThe layer")
(prompt la)
(prompt "is CURRENT!")
)
)
(if (= old nil)
(setq OLD la)
(setq OLD (strcat OLD "," la))
)
(setq ct (1+ ct))
)
(command "")
)
)
(princ)
(setvar "cmdecho" 0)
(prin1)
)
这个函数有一个问题,如果选择的图层包含了当前图层,就不能关闭
当前图层。
我想把它修改一下:如果当前选择的多个图层中包含了当前图层,
那么给用户一个是否关闭当前图层的选择,如果用户选择了y,则
关闭当前图层,如果用户选择了n,则不关闭当前图层。
谢谢了,就这么多!
如果可以的话,请帮忙注释一下这个程序!
谢谢了! 展开
1个回答
展开全部
;;; 2.2 LayerOffM 关闭物体所在的层(多选)
(Defun C:LayerOffM ()
(setvar "cmdecho" 0)
(command "_undo" "be")
(if (progn
(prompt "\n选取图元关闭其所在图层:")
(setq ss (ssget))
)
(progn
(setq ct 0
len (sslength ss)
cl (getvar "clayer")
tcmlb nil
)
(repeat len
(setq la (cdr (assoc 8 (entget (ssname ss ct)))))
(if (not (member la tcmlb))
(if (/= cl la)
(command "_layer" "off" la "")
(progn
(initget "Yes No")
(setq pdbz (getkword (strcat "\n\"" la "\"是当前层,要关闭吗?[Yes/No]<No>:")))
(if (= pdbz nil) (setq pdbz "No"))
(if (= pdbz "Yes")
(command "_layer" "off" la "y" "")
)
)
)
)
(setq tcmlb (cons la tcmlb)
ct (1+ ct)
)
)
)
(princ "\n未选取图元!")
)
(command "_undo" "e")
(setvar "cmdecho" 0)
(princ)
)
(Defun C:LayerOffM ()
(setvar "cmdecho" 0)
(command "_undo" "be")
(if (progn
(prompt "\n选取图元关闭其所在图层:")
(setq ss (ssget))
)
(progn
(setq ct 0
len (sslength ss)
cl (getvar "clayer")
tcmlb nil
)
(repeat len
(setq la (cdr (assoc 8 (entget (ssname ss ct)))))
(if (not (member la tcmlb))
(if (/= cl la)
(command "_layer" "off" la "")
(progn
(initget "Yes No")
(setq pdbz (getkword (strcat "\n\"" la "\"是当前层,要关闭吗?[Yes/No]<No>:")))
(if (= pdbz nil) (setq pdbz "No"))
(if (= pdbz "Yes")
(command "_layer" "off" la "y" "")
)
)
)
)
(setq tcmlb (cons la tcmlb)
ct (1+ ct)
)
)
)
(princ "\n未选取图元!")
)
(command "_undo" "e")
(setvar "cmdecho" 0)
(princ)
)
追问
能把这个程序大致注释一下吗?我对lisp懂的比较少,看得不是怎么明白
追答
;;; 2.2 LayerOffM 关闭物体所在的层(多选)
(Defun C:LayerOffM ()
(setvar "cmdecho" 0);设置为0,关闭命令在在命令行中的回显
(command "_undo" "be");设置要放弃的操作的起点
(if (progn
(prompt "\n选取图元关闭其所在图层:")
(setq ss (ssget));如果选到图元,则执行下面操作
)
(progn
(setq ct 0
len (sslength ss);选择集中的图元个数
cl (getvar "clayer");取得当前的图层名
tcmlb nil
)
(repeat len
(setq la (cdr (assoc 8 (entget (ssname ss ct)))));取选择集内图元所在的图层名
(if (not (member la tcmlb));如果图层名不在表tcmb中,则执行下操作
(if (/= cl la);如果图层不是当月图层,则关闭它
(command "_layer" "off" la "")
(progn
;如果是当前图层,则询问是否要关闭
(initget "Yes No")
(setq pdbz (getkword (strcat "\n\"" la "\"是当前层,要关闭吗?[Yes/No]:")))
(if (= pdbz nil) (setq pdbz "No"))
(if (= pdbz "Yes")
(command "_layer" "off" la "y" "")
)
)
)
)
(setq tcmlb (cons la tcmlb);将图层名加入到表tcmlb中
ct (1+ ct)
)
)
)
(princ "\n未选取图元!")
)
(command "_undo" "e")");设置要放弃的操作的止点
(setvar "cmdecho" 0)
(princ)
)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询