如何获取所有viewp的列表
请原谅这里的lisp新手,但是我如何调用给定布局中所有视口的列表?类似于(foreach lay(布局列表)?它可以嵌套在(foreach lay(layoutlist))这样的函数中吗?
简单地说,我想通过向现有lisp添加一些代码来锁定所有视口,在每个布局中设置一些其他变量。
谢谢 使用Jason在本讨论中提交的lisp例程(VPlock_unlock.lsp)锁定和解锁视口。
http://discussion.autodesk.com/forums/thread.jspa?threadID=468710 嗯,有:
(vports)
这将根据视口的标识号提供视口列表,但这将锁定所有视口:
(defun c:lkall (/ i ss ent)
(vl-load-com)
(if (setq i -1 ss (ssget "_X" '((0 . "VIEWPORT"))))
(while (setq ent (ssname ss (setq i (1+ i))))
(vla-put-displaylocked (vlax-ename->vla-object ent) :vlax-true)))
(princ))
李 这行得通吗?
(foreach vp (vports)
(vla-put-displaylocked (vlax-ename->vla-object vp) :vlax-true)
)
在更大的背景下(其余部分确实有效,但速度较慢):
(defun c:psfix ( / lay ct vp)
(vl-load-com)
(setq ct (getvar "ctab"))
(foreach lay (layoutlist)
(command "_LAYOUT" "_Set" lay "PSLTSCALE" 1)
(command "_layout" "_Set" lay "_mspace" "ANNOALLVISIBLE" 1 "_pspace")
)
(foreach vp (vports)
(vla-put-displaylocked (vlax-ename->vla-object vp) :vlax-true)
)
(setvar "msltscale" 1)
(setvar "ltscale" 1)
(setvar "ctab" ct)
);defun 不,因为(vports)返回一个视口标识号列表-我文章第二部分中的代码将锁定所有视口 试试这个。。
快速修改代码:
(defun c:psfix ( / ct lay i ss ent)
(vl-load-com)
(setq ct (getvar "ctab"))
(foreach lay (layoutlist)
(mapcar 'setvar '("CTAB" "PSLTSCALE") (list lay 1))
(vl-cmdf "_.mspace")
(setvar "ANNOALLVISIBLE" 1)
(vl-cmdf "_.pspace"))
(if (setq i -1 ss (ssget "_X" '((0 . "VIEWPORT"))))
(while (setq ent (ssname ss (setq i (1+ i))))
(vl-catch-all-apply 'vla-put-displaylocked
(list (vlax-ename->vla-object ent) :vlax-true))))
(mapcar 'setvar '("MSLTSCALE" "LTSCALE" "CTAB") (list 1 1 ct))
(princ))
很好,谢谢。
我试着坚持我所熟悉的(一点点)。。。
我希望你的版本也会更快。 也许我很笨,但你能评论一下,帮助我理解你在做什么吗?我对所有这些方法都不熟悉?
谢谢李
很好的发现。谢谢Mark 这不是问题,Cary-我更希望您理解我的代码在做什么,而不是仅仅接受它。
如果你还对什么事感到困惑,尽管问。
(defun c:psfix ( / ct lay i ss ent) ;; Initiate Defun and localise Vars
(vl-load-com);; Load Visual LISP Console
(setq ct (getvar "ctab")) ;; Store Current Layout
(foreach lay (layoutlist) ;; For Every Layout in the Drawing
(mapcar 'setvar '("CTAB" "PSLTSCALE") (list lay 1))
;; Apply the function 'setvar' to each argument in each list.
;; Setvar needs two arguments, sys var and value, so mapcar needs
;; two lists.
;; This is equivalent to putting (setvar "CTAB" lay) (setvar "PSLTSCALE" 1)
(vl-cmdf "_.mspace");; Equivalent to (command "_.mspace")
(setvar "ANNOALLVISIBLE" 1) ;; Set Sys Var ANNOALLVISIBLE to 1
(vl-cmdf "_.pspace");; Equivalent to (command "_.pspace")
); end foreach
(if (setq i -1 ss (ssget "_X" '((0 . "VIEWPORT"))))
;; If there are Viewports in the Database
(while (setq ent (ssname ss (setq i (1+ i))))
;; While we can get an entity name in the Selection Set
(vl-catch-all-apply ;; Apply the following function and catch any errors
;; This is like using 'apply' except the program will not crash if
;; there is an error executing the function.
'vla-put-displaylocked;; Property of the Viewport to determine if it is locked.
;; List of arguments that belong to 'vla-put-displaylocked'
(list
(vlax-ename->vla-object ent) ;; convert the ename to a VLA-object
:vlax-true) ;; Boolean True - hence the Viewport will be locked
) ; end vl-catch-all-apply
) ; end While
) ; end IF
(mapcar 'setvar '("MSLTSCALE" "LTSCALE" "CTAB") (list 1 1 ct))
;; Same logic as above - read about 'mapcar' to learn more.
(princ) ;; Exit Quietly - i.e. suppress last return
) ;; End Defun
李
PS>也许还可以在Visual LISP编辑器帮助文件中查找一些您不熟悉的函数——(命令行中的VLIDE)。
页:
[1]
2