About Performance Considerations (AutoLISP/ActiveX)

Repeated calls to access the AutoCAD Application, active Document, and ModelSpace objects should be avoided, as they negatively impact performance.

Note: ActiveX support in AutoLISP is limited to Windows only.

You should design your applications to obtain these objects one time, and refer to the obtained object pointers throughout the application. The following code illustrates 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)

The 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.