Author Topic: Help With Reacotr Code.....!  (Read 2207 times)

0 Members and 1 Guest are viewing this topic.

Vince

  • Newt
  • Posts: 55
Help With Reacotr Code.....!
« on: July 16, 2008, 11:06:28 AM »
I made an attempt to create a "Document Reactor" that would automatically run when the user switches between drawing files that have been already opened. However, it appears that as the user switches from one drawing to another several times the reactor will fire multiple times when you switch to a drawing, not just once.

It would be greatly appreciated if anyone can look at the sample code below and identify what I have done incorrectly......!


####Start Code
Code: [Select]
(vl-load-com)
(setq mac_documentbecamecurrent_reactor nil
mac_reactors_list nil
mac_item nil
mac_reactor nil
)

(if (setq mac_reactors_list (vlr-reactors :vlr-docmanager-reactor))
 (progn (foreach mac_item mac_reactors_list
  (if (= (vlr-data (cadr mac_item)) "MAC-DOCUMENTBECAMECURRENT-REACTOR")
  (setq mac_documentbecamecurrent_reactor (cadr mac_item))
 )
)

(if mac_documentbecamecurrent_reactor
  (if (= (vlr-added-p mac_documentbecamecurrent_reactor) nil)
   (vlr-add mac_documentbecamecurrent_reactor)
  )
  (setq mac_reactor (vlr-docmanager-reactor
  "MAC-DOCUMENTBECAMECURRENT-REACTOR"
  '((:vlr-documentbecamecurrent .
  mac-reactor-documentbecamecurrent))
  )
  )
 )
)

(setq mac_reactor (vlr-docmanager-reactor
 "MAC-DOCUMENTBECAMECURRENT-REACTOR"
  '((:vlr-documentbecamecurrent . mac-reactor-documentbecamecurrent))
  )
 )
)

(setq mac_documentbecamecurrent_reactor nil
mac_reactors_list nil
mac_item nil
mac_reactor nil
)

(defun mac-reactor-documentbecamecurrent (mac_reactor mac_info /)

(alert "Reactor has run")
(Princ)
)
#####End Code

Thank you in advance for any assistance.

Regards,
Vince


<edit: code tags added>
« Last Edit: July 16, 2008, 11:39:45 AM by CAB »

deegeecees

  • Guest
Re: Help With Reacotr Code.....!
« Reply #1 on: July 16, 2008, 11:21:47 AM »
I find those types of reactors are a bit easier to manage in VBA, rather than Lisp, but that may just be from lack of knowledge on my part.

In VBA, you could use the AcadDocument_Activate event to trigger your code.

Vince

  • Newt
  • Posts: 55
Re: Help With Reacotr Code.....!
« Reply #2 on: July 16, 2008, 11:33:00 AM »
Thank you for your response,

Since I would like this reactor to fire when the user switches from one drawing to another, do you have any suggestions on another type of reactor to use....??

Regards,
Vince

deegeecees

  • Guest
Re: Help With Reacotr Code.....!
« Reply #3 on: July 16, 2008, 11:49:22 AM »
Not in Lisp, but there are others here that will probably be along to help.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help With Reacotr Code.....!
« Reply #4 on: July 16, 2008, 11:55:32 AM »
No time to look at your routine but maybe this will help:
http://www.theswamp.org/index.php?topic=5406.0
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Help With Reacotr Code.....!
« Reply #5 on: July 17, 2008, 01:21:12 PM »
Interesting, fires three times.  Wonder why?

Maybe try setting a flag and check for it:

First reaction: (setq MyFlag T)
subsequent reactions (if (not MyFlag) . . . )

James Buzbee
Windows 8