求一个cad lisp命令!
我有4个问题请高手一一解答1.请帮我翻译下面一串代码的意思,每句都要。(defunc:1()(setqgb(getvar"cmdecho"))(setvar"cmdech...
我有4个问题
请高手一一解答
1.请帮我翻译下面一串代码的意思,每句都要。
(defun c:1()
(setq gb (getvar "cmdecho"))
(setvar "cmdecho" 0)
(princ "锁定选择物体的图层: ")
(setq s0 (ssget))
(setq i 0)
(while (ssname s0 i)
(setq laname (cdr (assoc 8 (entget (ssname s0 i)))))
(command "layer" "lo" laname "" )
(setq i (1+ i))
)
(setvar "cmdecho" gb))
2.我自己写了一个代码,但是好像不对,请帮我看一下。
(defun c:89()
(setq gb (getvar "cmdecho"))
(setvar "cmdecho" 0)
(princ "解锁选择物体的图层: ")
(setq s0 (ssget))
(setq i 0)
(while (ssname s0 i)
(setq laname (cdr (assoc 8 (entget (ssname s0 i)))))
(command "vplayer" "f" laname "" )
(setq i (1+ i))
)
(setvar "cmdecho" gb))
3.根据2提出来的问题,我想求一个cad冻结视口的lisp命令,效果要和vplayer 然后选择f的命令效果一样。
4.cad 模型空间和图纸空间来回切换是通过TILEMODE变量1或者0实现的,想求一个lisp代码,只需一个命令就可以来回切换他们。 展开
请高手一一解答
1.请帮我翻译下面一串代码的意思,每句都要。
(defun c:1()
(setq gb (getvar "cmdecho"))
(setvar "cmdecho" 0)
(princ "锁定选择物体的图层: ")
(setq s0 (ssget))
(setq i 0)
(while (ssname s0 i)
(setq laname (cdr (assoc 8 (entget (ssname s0 i)))))
(command "layer" "lo" laname "" )
(setq i (1+ i))
)
(setvar "cmdecho" gb))
2.我自己写了一个代码,但是好像不对,请帮我看一下。
(defun c:89()
(setq gb (getvar "cmdecho"))
(setvar "cmdecho" 0)
(princ "解锁选择物体的图层: ")
(setq s0 (ssget))
(setq i 0)
(while (ssname s0 i)
(setq laname (cdr (assoc 8 (entget (ssname s0 i)))))
(command "vplayer" "f" laname "" )
(setq i (1+ i))
)
(setvar "cmdecho" gb))
3.根据2提出来的问题,我想求一个cad冻结视口的lisp命令,效果要和vplayer 然后选择f的命令效果一样。
4.cad 模型空间和图纸空间来回切换是通过TILEMODE变量1或者0实现的,想求一个lisp代码,只需一个命令就可以来回切换他们。 展开
推荐于2017-12-25 · 知道合伙人软件行家
关注
展开全部
图层锁定或解锁,代码如下。
;图层锁定及解锁
(defun c:tes ( / ent lay1)
(vl-load-com)
(while (and (setq ent (entsel "\n请选择要锁定或解锁的图元")) (setq lay1 (cdr (assoc 8 (entget (car ent))))))
(w1712251 lay1)
)
(princ)
)
(defun w1712251 (lay1 / lay lay1)
(vlax-for lay (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(if (= (vla-get-name lay) lay1)
(progn
(if (= (vla-get-lock lay) :vlax-true);如果图层锁定
(vla-put-lock lay :vlax-false) ;解锁
(vla-put-lock lay :vlax-true) ;锁定
)
)
)
)
)
展开全部
在百思论坛上找到的,用AutoCAD2008自带的Visual LISP编辑器存入,并用加载应用程序运行过,代码如下
laymod.lsp
;__________________________
;解决R14“bonus”工具的移植
;图层管理工具
;-------------------------------------------
;图层对象选择,将标注归入dim层,文字归入txt层
;___________________________________________
(defun C:laymod(/ lm_ssd lm_sst)
(if (not (tblsearch "layer" "DIM"))
(command "-layer" "n" "DIM" "c" "1""DIM"""));endif
(if (not (tblsearch "layer" "TXT"))
(command "-layer" "n" "TXT" "c" "1""TXT"""));endif
(setq lm_ssd (ssget "X" '((0 . "DIMENSION")))
lm_sst (ssget "X" '((-4 . "<or")(0 . "TEXT")(0 . "MTEXT")(-4 . "or>"))));endsetq
(if lm_ssd (command "chprop" lm_ssd "" "la" "DIM"""))
(if lm_sst (command "chprop" lm_sst "" "la" "TXT"""))
);end defun
;-------------------------------------
;图层孤立显示,通过选择对象单显某图层
;_____________________________________
(defun C:layiso(/ l9_ss l9_ent l9_lay ii)
(setq l9_ss "" ii 0)
(princ "\n选择要保留显示的图层:")
(setq l9_ss (ssget))
(if l9_ss (command "-layer""off""*""y"""))
(repeat (sslength l9_ss)
(setq l9_ent (entget (ssname l9_ss ii)))
(setq l9_lay (cdr (assoc 8 l9_ent)) ii (1+ ii))
(command "-layer""on" l9_lay "")
);end repeat
);end defun layiso
;--------------------------
;打开所有图层
;__________________________
(defun C:layon()(command "-layer""on""*"""))
;--------------------------
;解除所有图层锁定
;__________________________
(defun C:layul()(command "-layer""u""*"""))
;--------------------------
;解除所有图层冻结
;__________________________
(defun C:layuk()(command "-layer""t""*"""))
;--------------------------
;通过选择解除图层锁定
;__________________________
(defun C:layulk(/ l9_ss l9_ent l9_lay)
(setq l9_ss (entsel "\n选择要解锁的图层:"))
(while l9_ss
(setq l9_ent (entget (car l9_ss)))
(setq l9_lay (cdr (assoc 8 l9_ent)))
(command "layer""u" l9_lay"")
(setq l9_ss (entsel "\n选择要解锁的图层:"))
);end while
);end defun
;--------------------------
;通过选择锁定图层
;__________________________
(defun C:laylck(/ l9_ss l9_ent l9_lay)
(setq l9_ss (entsel "\n选择要锁定的图层:"))
(while l9_ss
(setq l9_ent (entget (car l9_ss)))
(setq l9_lay (cdr (assoc 8 l9_ent)))
(command "layer""u" l9_lay"")
(setq l9_ss (entsel "\n选择要锁定的图层:"))
);end while
);end defun
;--------------------------
;通过选择冻结图层
;_________________
(defun C:layfrz(/ l9_ss l9_ent l9_lay l9_clay ii)
(setq l9_clay (getvar "clayer"))
(princ "\n选取冻结图层参考对象: ")
(setq l9_ss (ssget))
(setq ii 0)
(command "-layer")
(repeat (sslength l9_ss)
(setq l9_ent (entget (ssname l9_ss ii)))
(setq l9_lay (cdr (assoc 8 l9_ent)))
(command "f" l9_lay)
(setq ii (1+ ii))
);end repeat
(command "")
);end defun layfrz
;--------------------------
;通过选择隐藏图层
;__________________________
(defun C:layoff(/ l9_ss l9_ent l9_lay l9_clay ii)
(princ "\n选取隐藏图层参考对象: ")
(setq l9_ss (ssget))
(setq l9_clay (getvar "clayer"))
(setq ii 0)
(command "-layer")
(repeat (sslength l9_ss)
(setq l9_ent (ssname l9_ss ii))
(setq l9_lay (cdr (assoc 8 (entget l9_ent))))
(if (/= l9_lay l9_clay)
(command "off" l9_lay)(command "off" l9_lay"y")
);end if
(setq ii (1+ ii))
);end repeat
(command "")
);end defun layoff
;--------------------------
(princ "\n---------->> 图层调整
(laymod)layiso/layon/layuk/layulk/laylck/layfrz/layoff<<----------")
(prin1)
laymod.lsp
;__________________________
;解决R14“bonus”工具的移植
;图层管理工具
;-------------------------------------------
;图层对象选择,将标注归入dim层,文字归入txt层
;___________________________________________
(defun C:laymod(/ lm_ssd lm_sst)
(if (not (tblsearch "layer" "DIM"))
(command "-layer" "n" "DIM" "c" "1""DIM"""));endif
(if (not (tblsearch "layer" "TXT"))
(command "-layer" "n" "TXT" "c" "1""TXT"""));endif
(setq lm_ssd (ssget "X" '((0 . "DIMENSION")))
lm_sst (ssget "X" '((-4 . "<or")(0 . "TEXT")(0 . "MTEXT")(-4 . "or>"))));endsetq
(if lm_ssd (command "chprop" lm_ssd "" "la" "DIM"""))
(if lm_sst (command "chprop" lm_sst "" "la" "TXT"""))
);end defun
;-------------------------------------
;图层孤立显示,通过选择对象单显某图层
;_____________________________________
(defun C:layiso(/ l9_ss l9_ent l9_lay ii)
(setq l9_ss "" ii 0)
(princ "\n选择要保留显示的图层:")
(setq l9_ss (ssget))
(if l9_ss (command "-layer""off""*""y"""))
(repeat (sslength l9_ss)
(setq l9_ent (entget (ssname l9_ss ii)))
(setq l9_lay (cdr (assoc 8 l9_ent)) ii (1+ ii))
(command "-layer""on" l9_lay "")
);end repeat
);end defun layiso
;--------------------------
;打开所有图层
;__________________________
(defun C:layon()(command "-layer""on""*"""))
;--------------------------
;解除所有图层锁定
;__________________________
(defun C:layul()(command "-layer""u""*"""))
;--------------------------
;解除所有图层冻结
;__________________________
(defun C:layuk()(command "-layer""t""*"""))
;--------------------------
;通过选择解除图层锁定
;__________________________
(defun C:layulk(/ l9_ss l9_ent l9_lay)
(setq l9_ss (entsel "\n选择要解锁的图层:"))
(while l9_ss
(setq l9_ent (entget (car l9_ss)))
(setq l9_lay (cdr (assoc 8 l9_ent)))
(command "layer""u" l9_lay"")
(setq l9_ss (entsel "\n选择要解锁的图层:"))
);end while
);end defun
;--------------------------
;通过选择锁定图层
;__________________________
(defun C:laylck(/ l9_ss l9_ent l9_lay)
(setq l9_ss (entsel "\n选择要锁定的图层:"))
(while l9_ss
(setq l9_ent (entget (car l9_ss)))
(setq l9_lay (cdr (assoc 8 l9_ent)))
(command "layer""u" l9_lay"")
(setq l9_ss (entsel "\n选择要锁定的图层:"))
);end while
);end defun
;--------------------------
;通过选择冻结图层
;_________________
(defun C:layfrz(/ l9_ss l9_ent l9_lay l9_clay ii)
(setq l9_clay (getvar "clayer"))
(princ "\n选取冻结图层参考对象: ")
(setq l9_ss (ssget))
(setq ii 0)
(command "-layer")
(repeat (sslength l9_ss)
(setq l9_ent (entget (ssname l9_ss ii)))
(setq l9_lay (cdr (assoc 8 l9_ent)))
(command "f" l9_lay)
(setq ii (1+ ii))
);end repeat
(command "")
);end defun layfrz
;--------------------------
;通过选择隐藏图层
;__________________________
(defun C:layoff(/ l9_ss l9_ent l9_lay l9_clay ii)
(princ "\n选取隐藏图层参考对象: ")
(setq l9_ss (ssget))
(setq l9_clay (getvar "clayer"))
(setq ii 0)
(command "-layer")
(repeat (sslength l9_ss)
(setq l9_ent (ssname l9_ss ii))
(setq l9_lay (cdr (assoc 8 (entget l9_ent))))
(if (/= l9_lay l9_clay)
(command "off" l9_lay)(command "off" l9_lay"y")
);end if
(setq ii (1+ ii))
);end repeat
(command "")
);end defun layoff
;--------------------------
(princ "\n---------->> 图层调整
(laymod)layiso/layon/layuk/layulk/laylck/layfrz/layoff<<----------")
(prin1)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
(defun C:8 (/ ES EN EL A)
(princ "冻结视口图层.")
(setq ES (ssget) A 0 EN "" EL nil FL nil)
(while (/= EN nil)
(setq EN (ssname ES A) EL (cons EN EL) A (1+ A)))
(setq EL (cdr EL) FL (cdr (assoc ' 8 (entget (car EL)))) EL (cdr EL))
(repeat (- A 2)
(setq EN (cdr (assoc ' 8 (entget (car EL))))
FL (strcat EN "," FL) EL (cdr EL)) )
(command "vpLAYER" "F" (eval FL) "")
(princ))
(princ "冻结视口图层.")
(setq ES (ssget) A 0 EN "" EL nil FL nil)
(while (/= EN nil)
(setq EN (ssname ES A) EL (cons EN EL) A (1+ A)))
(setq EL (cdr EL) FL (cdr (assoc ' 8 (entget (car EL)))) EL (cdr EL))
(repeat (- A 2)
(setq EN (cdr (assoc ' 8 (entget (car EL))))
FL (strcat EN "," FL) EL (cdr EL)) )
(command "vpLAYER" "F" (eval FL) "")
(princ))
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
(command "vplayer" "f" laname "" )有问题:
"vplayer"应为"layer"吧。
"f" 应为"u" 吧。
"vplayer"应为"layer"吧。
"f" 应为"u" 吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询