CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

创建对象反应器 (AutoLISP/ActiveX)

2024-5-18 19:04| 发布者: admin| 查看: 17| 评论: 0|原作者: admin|来自: AutoCAD

创建对象反应器 (AutoLISP/ActiveX)

创建一个对象反应器,该反应器在修改对象时显示一条消息。

注意:AutoLISP 中的 ActiveX 支持仅限于 Windows。
  1. 确定要用于反应器的对象事件。
  2. 定义将用作反应器回调的函数。
  3. 定义用于创建或获取要在其中连接反应器的 VLA 对象的函数。
  4. 创建反应堆;语句,用于创建 reactor 对象、分配特定于应用程序的数据、关联 reactor 应使用哪些 VLA 对象以及指定回调函数。
  5. 加载、运行和测试 AutoLISP 代码。

  1. 创建新的 LSP 文件并输入以下内容:
    ; 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))))
    )
  2. 保存 LSP 文件,然后将其加载到 AutoCAD 中。
  3. 在 AutoCAD 图形窗口中,指定圆的中心点和半径。
  4. 创建圆圈后,选择它以显示其夹点。单击其中一个外部夹点以更改圆的半径。

    您应该会在 STRETCH 选项的提示后看到一条消息,类似于以下内容:

    指定拉伸点或 [基点/复制/撤消/eXit]:半径为 3.75803


路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-6-27 15:47

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部