CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoLISP 开发指南

处理非线性反应器序列

2023-1-5 06:28| 发布者: admin| 查看: 316| 评论: 0|来自: AutoCAD

最后一个重要细节涉及当用户使用专用的 GRIP 命令修改折线时,AutoCAD 中命令/反应器序列中的一个怪癖。这些命令(如 GRIP_MOVE 和 GRIP_ROTATE)在选择对象的夹点并单击鼠标右键后可从快捷菜单中使用。反应器序列不像简单的 MOVE 或 ERASE 命令那样线性。实际上,用户在另一个命令中正在更改为不同的命令。若要演示此情况,可以加载第 6 课中跟踪反应器事件序列的代码。或者只需查看以下带批注的 Visual LISP 控制台窗口输出,看看会发生什么情况:

;; To start, select the polyline and some of the circles by using a 
;; crossing selection box. The items in the selection set-- 
;; the chosen circles and the polyline--are now shown with grips on.
;; To initiate the sequence, click on one of the polyline grips:
(GP:COMMAND-WILL-START #<VLR-Command-reactor> (GRIP_STRETCH))

;; Now change the command to a move by right-clicking and choosing
;; MOVE from the pop-up menu.  Notice that the command-ended
;; reactor fires in order to close out the GRIP_STRETCH command
;; without having fired an object reactor event:
(GP:COMMAND-ENDED #<VLR-Command-reactor> (GRIP_STRETCH))
(GP:COMMAND-WILL-START #<VLR-Command-reactor> (GRIP_MOVE))

;; Now drag the outline (and the selected circles) to a new location.
(GP:OUTLINE-CHANGED #<VLA-OBJECT IAcadLWPolyline 028f3188> 
                 #<VLR-Object-reactor> nil)
(GP:COMMAND-ENDED #<VLR-Command-reactor> (GRIP_MOVE))

这表明您无法确定在所有情况下都会调用对象反应器回调。

这个序列中有一个相关的怪癖。即使在最终命令结束回调期间,也无法删除仍属于夹点选择集的圆圈。这些圆圈仍然由AutoCAD打开。如果在命令结束回调期间尝试擦除它们,则可能会使 AutoCAD 崩溃。若要解决此问题,可以使用另一个全局变量来存储指向磁贴对象的指针列表,直到可以删除它们。

处理非线性反应器序列

  1. 将以下函数添加到gpreact.lsp文件中:
    (defun gp:erase-tiles (reactor / reactorData tiles tile)
      (if (setq reactorData (vlr-data reactor))
        (progn
          ;; Tiles in the path are stored as data in the reactor.
          (setq tiles (cdr (assoc 100 reactorData)))
          ;; Erase all the existing tiles in the path.
          (foreach tile tiles
              (if (and (null (member tile *Safe-to-Delete*))
                     (not (vlax-erased-p tile))
                     )
                  (progn
                     (vla-put-visible tile 0)
                     (setq *Safe-to-Delete* (cons tile *Safe-to-Delete*))
                  )
              )
          )
          (vlr-data-set reactor nil)
          ) 
        )
     )

    此新功能将用于擦除图块的第一阶段。请注意,这些磁贴实际上并未被擦除:它们不可见,并被添加到名为的全局变量中。*Safe-to-Delete*

  2. 将以下函数添加到gpreact.lsp文件中:
    (defun Gp:Safe-Delete (activeCommand)
      (if (not (equal
          (strcase (substr activeCommand 1 5))
            "GRIP_"
          )
      )
      (progn
         (if *Safe-to-Delete*
            (foreach Item *Safe-to-Delete*
              (if (not (vlax-erased-p Item))
                (vla-erase item)
              )
            )
          )
          (setq *Safe-to-Delete* nil)
          )
        )
     )

    可以在未执行GRIP_MOVE或GRIP_STRETCH命令时调用此函数。


路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-27 11:02

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部