应避免重复调用以访问 AutoCAD 应用程序、活动文档和 ModelSpace 对象,因为它们会对性能产生负面影响。 注意:AutoLISP 中的 ActiveX 支持仅限于 Windows。
应将应用程序设计为一次性获取这些对象,并在整个应用程序中引用获取的对象指针。下面的代码演示了可以定义的三个函数,以分别返回 Application、active Document 和 ModelSpace 对象: (setq *acad-object* nil) ; Initialize global variable
(defun acad-object ()
(cond (*acad-object*) ; Return the cached object
(t
(setq *acad-object* (vlax-get-acad-object))
)
)
)
(setq *active-document* nil) ; Initialize global variable
(defun active-document ()
(cond (*active-document*) ; Return the cached object
(t
(setq *active-document* (vla-get-activedocument (acad-object)))
)
)
)
(setq *model-space* nil) ; Initialize global variable
(defun model-space ()
(cond (*model-space*) ; Return the cached object
(t
(setq *model-space* (vla-get-modelspace (active-document)))
)
)
)
例如,您可以使用以下函数调用绘制一个圆: (vla-addCircle (model-space) (vlax-3d-point '(3.0 3.0 0.0)) 2.0) model-space 函数返回活动文档的模型空间,如有必要,使用 active-document 函数访问 Document 对象。如有必要,active-document 函数又会调用 acad-object 来获取 Application 对象。 相关概念 |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 14:28
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.