CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 文档中心

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

2023-1-8 00:08| 发布者: admin| 查看: 265| 评论: 0|来自: AutoCAD

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

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

注意: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. 创建圆后,选择它以显示其夹点。单击其中一个外部夹点以更改圆的半径。

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

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


路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 12:23

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部