Repeated calls to access the AutoCAD Application, active Document, and ModelSpace objects should be avoided, as they negatively impact performance. You should design your applications to obtain these objects one time, and refer to the obtained object pointers throughout the application.
The following code examples illustrate three functions you can define to return the Application, active Document, and ModelSpace objects, respectively:
(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)))
)
)
)
For example, you can draw a circle using the following function call:
(vla-addCircle (model-space) (vlax-3d-point '(3.0 3.0 0.0)) 2.0)
model-space function returns the model space of the active document, using the active-document function to access the Document object, if necessary. The active-document function, in turn, calls acad-object to obtain the Application object, if necessary.
The