オブジェクト リアクタを作成するには(AutoLISP/ActiveX)

オブジェクトが修正されるとメッセージを表示するオブジェクト リアクタを作成します。

注: AutoLISP での ActiveX のサポートは Windows のみに制限されています。
  1. リアクタに使用するオブジェクト イベントを決定します。
  2. リアクタのコールバックとして使用する関数を定義します。
  3. リアクタをアタッチする VLA オブジェクトを作成または取得する関数を定義します。
  4. リアクタ(リアクタ オブジェクトを作成する文)を作成し、アプリケーション固有のデータを割り当て、リアクタが動作する VLA オブジェクトを関連付け、コールバック関数を指定します。
  5. AutoLISP コードをロードし、実行し、テストします。

  1. AutoCAD のコマンド プロンプトに対して vlide と入力します。
  2. Visual LISP で、[ファイル] [ファイルを新規作成]をクリックします。
  3. 新しい Visual LISP のテキスト エディタ ウィンドウで、次を入力します。
    ; Define the callback function to use for the reactor
    ; The following function prints a message with the circle’s radius
    (defun print-radius (notifier-object reactor-object parameter-list)
      (vl-load-com)
      (cond
        (
         (vlax-property-available-p
           notifier-object
           "Radius"
         )
         (princ "The radius is ")
         (princ (vla-get-radius notifier-object))
        )
      )
    )
    
    ; Create a variable to hold the circle object that
    ; will be used as the owner of the reactor
    (setq myCircle
      ; Prompt for the center point and radius:
      (progn
        (setq ctrPt (getpoint "\nCircle center point: ")
                 radius (distance ctrPt (getpoint ctrpt "\nRadius: "))
        )
    
        ; Add a circle to the drawing model space. Nest the function
        ; calls to obtain the path to the current drawing's model
        ; space: AcadObject > ActiveDocument > ModelSpace
        (vla-addCircle
          (vla-get-ModelSpace
            (vla-get-ActiveDocument (vlax-get-acad-object))
          )
          (vlax-3d-point ctrPt)
          radius
        )
      )
    )
    
    ; Create the reactor and pass it the circle object, 
    ; application-specific data, and callback function.
    (if (= circleReactor nil)
      (setq circleReactor (vlr-object-reactor (list myCircle)
        "Circle Reactor" '((:vlr-modified . print-radius))))
    )
  4. [ツール] [エディタ内のテキストをロード]をクリックします。
  5. AutoCAD の作図ウィンドウで、円の中心点と半径を指定します。
  6. 円を作成したら、選択してグリップを表示します。外側のグリップの 1 つをクリックして、円の半径を変更します。

    STRETCH[ストレッチ]コマンドのオプションのプロンプトの後に、次のようなメッセージが表示されるはずです。

    ストレッチ点を指定 または [基点(B)/複写(C)/元に戻す(U)/終了(X)]: 半径は 3.75803