sfzyr 发表于 2023-10-2 23:05:21

关于vlr-insert-reactor反应器的应用问题

我想在插入某个对象时,获得这个对象,并判定是否是一个特定的对象如块名是“aaa”,想用反应器来实现,但是vlr-insert-reactor 并不启作用,我检索了这个问题,网络上关于这个应用的案例非常少,并找到了一个英文网站,一个网友有我一样的疑问,我希望能采用这个反应器来获得插入的对象。这个反应器怎么不起作用了,还是我哪里理解错了,它的正确用法是怎样的呢,希望各位版主和高手都能给个回复,万分感谢。代码如下:


;;;=======创建insert反应器*at_inst_reactor*及回调函数==============================
(defun at_inst_reactor ()
(if (not *instReactor*)
    (setq *instReactor*
           (vlr-insert-reactor
             nil
             '((:vlr-beginInsert . inst-begin)
             (:vlr-endInsert . inst-ended)
              )
           )
    )
)
);_定义insert反应器*instReactor*
(defun inst-begin (reactor-object parameterlist)
(princ "inst-begin<")
(vl-princ-to-string parameterlist)
(princ ">\n")
)
(defun inst-ended (reactor-object parameterlist)
(princ "inst-ended<")
(vl-princ-to-string parameterlist)
(princ ">\n")
)

=========================================
英文网站的问题如下:why does vlr-insert-reactor doesn't work? (augi.com)
why does vlr-insert-reactor doesn't work?I want do some thing when a block was been inserted into autocad,so I make a reactor like this:

(vlr-insert-reactor nil '((:vlr-endinsert . vlr-trace-reaction)))

but it doesn't work when I have inserted any block. It seems like this reactor was never exsited.

Hope you can help me. Thanks.============================================Re: why does vlr-insert-reactor doesn't work?Welcome to AUGI and congrats on your first post.

I have always used a command reactor for causing commands to fire when inserting a block.
Code:
(if    (not Command_Ending_Reactor)      (setq Command_Ending_Reactor         (vlr-command-reactor         nil         '((:vlr-commandended          .          Command_Ended_Command         )      )         ) ;_ end of vlr-command-reactor      ) ;_ end of setq      () ;_ the reactor is already loaded    ) ;_ end of if
then I define my command ended command with the in reactor name and the in command, and compare the in command to the command I am looking for, in your case "insert" or "-insert" If it matches, it will run the program.





sfzyr 发表于 2023-10-3 13:37:13

这个是我用错了,还是CAD版本的问题了,我的版本是autocad 机械版 2021.各位高手,看看哪里错了,折腾好几天,搜罗了好几天,没招到答案。

jun353835273 发表于 2023-10-3 21:23:47

(defun blkstarted (reac data)

(if (wcmatch (car data) "INSERT")
   (progn
   (alert "INSERT"))
)
(princ)
)

(defun blkended (reac data)

(if (wcmatch (car data) "INSERT")
   (progn
   (alert "hh INSERT"))
)
(princ)
)

(vlr-command-reactor
"My Reactor"
'((:VLR-commandWillStart . blkstarted)
   (:VLR-commandEnded . blkended)

)
)
试一试用命令反应器看看能不能操作

sfzyr 发表于 2023-10-4 00:34:42

jun353835273 发表于 2023-10-3 21:23
试一试用命令反应器看看能不能操作

这个只是知道了用了INSERT命令,这个不知道是否插入了特定的块对象。还需要检测到这个命令后,去检测文档数据是否插入了新的指定对象,这个比较麻烦。

sfzyr 发表于 2023-10-4 00:38:47

我使用CTRL+V,时,好像触发了:vlr-endInsert事件,难道这个inset-reactor,在插入对象时不启用?可能是真没有理解这个反应器的应用。

dcl1214 发表于 2023-10-4 10:41:26

只要用到了反应器,所有代码尽可能多用vl-catch-all-apply,否则,各种奇葩问题
页: [1]
查看完整版本: 关于vlr-insert-reactor反应器的应用问题