AutoCAD Application オブジェクト、アクティブな Document オブジェクト、および Modelspace オブジェクトにアクセスする呼び出しを繰り返すと、パフォーマンスに悪影響を及ぼすため避けてください。
これらのオブジェクトを一度に取得して、アプリケーション全体を通して取得したオブジェクトのポインタを参照するようアプリケーションを設計してください。次のコードは、Application、アクティブな Document オブジェクト、および Modelspace オブジェクトを返す 3 つの関数の定義を示しています。
(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 関数は、必要な場合は Document オブジェクトにアクセスする active-document 関数を使用して、アクティブなドキュメントのモデル空間を返します。順に active-document 関数は、必要な場合は Application オブジェクトを取得する acad-object 関数を呼び出します。