Author Topic: Reactors and SDI vs MDI  (Read 5557 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Reactors and SDI vs MDI
« on: June 01, 2005, 06:38:02 PM »
So I have been using code that Se7en thought was nice and clean
Quote from: Se7en
" (or jmm:plot_reactor
(setq jmm:plot_reactor (vlr-editor-reactor nil '((:vlr-commandEnded . jmm:cmdEnd))))) "

...Nice trick Jeff.

Thats "clean" I like that.
which is precisely why I started using it. I don't use reactors that much, however, so I never noticed this before. Using the code found in THIS thread, load it into a drawing while SDI=0. Open another drawing and type (vlr-reactors), you will get nil, which is what I expected.

Now start another instance of Acad, this time with SDI=1. Again load the code and verify that the reactor is working. Also, type !jmm:plot_reactor at the command line and the reactor will be listed. Now open another drawing....you should see errors as it is loading like this: "; error: no function definition: JMM:CMDEND" This is correct, as I haven 't loaded those defuns to this drawing. However, typing (vlr-reactors) now shows that a reactor is still present! The jmm:plot_reactor symbol is no longer valid, but the reactor is......how can this be in a lisp environment that normally does not carry from dwg to dwg? What can i do to avoid this? Also, since the reactor is already loaded, it allows another, identical, reactor to be loaded if I only use the check shown above. Any simple ways of dealing with this?

thanks,
Jeff

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Reactors and SDI vs MDI
« Reply #1 on: June 01, 2005, 06:53:28 PM »
Huh?!

I havent messed with Reactors in a while, so im prolly not that good of use. BUT let me wrap my brain around that "loading thing" a bit.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Reactors and SDI vs MDI
« Reply #2 on: June 01, 2005, 06:58:40 PM »
Oh i got it! (Duh!?)

Its not the reactor or the "enviroment" its your 'Or' statment thats causing that.

Command: (or
           a
           (progn (princ "\n\"a\" isnt set.") (setq a 1)))

"a" isnt set.T

Command: !a
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Reactors and SDI vs MDI
« Reply #3 on: June 01, 2005, 07:18:24 PM »
...Agian, I appologise Jeff; I'm sorry, you wanted to know how to deal with that? (I just saw your last statment as I was scrolling up.)

In your "or" statment you shouldnt execute a statment like that; you should check to see if the reactor exists. Something like this:
Code: [Select]
(or
  jmm:plot_reactor
  (cond
     ((and
        (vlr-reactors :VLR-Editor-Reactor)
        (vlr-added-p jmm:plot_reactor)))
     ((setq jmm:plot_reactor
            (vlr-editor-reactor nil '((:vlr-commandEnded . jmm:cmdEnd)))))))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Reactors and SDI vs MDI
« Reply #4 on: June 01, 2005, 07:26:31 PM »
Quote from: Se7en
Oh i got it! (Duh!?)

Its not the reactor or the "enviroment" its your 'Or' statment thats causing that.

Um, nope. Let me try this again. After loading the reactor into the first opened drawing where SDI>0, I open a new drawing (which closes the first one) and I don't load ANY code, I get this:
Command: AECOPEN

Closing Autodesk Map project...

Opening an AutoCAD 2000 format file.

Regenerating model.

Command:
Command:
Initializing...
; error: no function definition: JMM:CMDEND


Command:
AutoCAD Express Tools Copyright © 2000 Autodesk, Inc.
; error: no function definition: JMM:CMDEND

AutoCAD menu utilities loaded.; error: no function definition: JMM:CMDEND
; error: no function definition: JMM:CMDEND

Command: (vlr-reactors)
((:VLR-Editor-Reactor #<VLR-Editor-Reactor>))

Command: !jmm:plot_reactor
nil

So that bit of code: (or sym (setq sym.....)) works great to keep it from reloading in the MDI arena, but when in SDI you get this when loading the first time in the second drawing:
Command: (vlr-reactors)
((:VLR-Editor-Reactor #<VLR-Editor-Reactor> #<VLR-Editor-Reactor>)) and the event is triggered twice. Now if I open a third drawing, guess what....yep, load my handy doody reactor and it gets fired 3 times.....

Does that 'splain it a bit better?

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Reactors and SDI vs MDI
« Reply #5 on: June 01, 2005, 07:37:01 PM »
OK, John,
Thanks for the kickstart...I think that this solves it, although I'm still not sure how the reactor gets carried from dwg to dwg....

Code: [Select]

(or jmm:plot_reactor
    (setq jmm:plot_reactor (cadr (car (vlr-reactors :vlr-editor-reactor))))
    (setq jmm:plot_reactor (vlr-editor-reactor nil '((:vlr-commandEnded . jmm:cmdEnd)))))
And this works providing my plot reactor is the first of any other editor-reactors that might be loaded.....if there are others, I'm unsure of how to differntiate between them.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Reactors and SDI vs MDI
« Reply #6 on: June 01, 2005, 07:55:06 PM »
http://groups-beta.google.com/group/autodesk.autocad.customization/browse_thread/thread/4c42da98985709ba/00cf3ccee8d37743?q=vlr-object&rnum=6&hl=en#00cf3ccee8d37743

Jeff, Have you had a look at Eric Schneider's code from early days. ?

.. a couple previous to the one shown ..
(defun vlr-object .....
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Reactors and SDI vs MDI
« Reply #7 on: June 01, 2005, 08:12:02 PM »
Thanks Kerry. No, I hadn't seen that code...and now that I have I think I hurt something, like one of my last remaining brain cells :)

I will continue some testing on this tomorrow.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Reactors and SDI vs MDI
« Reply #8 on: June 01, 2005, 08:15:34 PM »
Quote
.. and now that I have I think I hurt something,  ..


I know the feeling
You should see my 'too-hard' folder ..

:D
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Reactors and SDI vs MDI
« Reply #9 on: June 02, 2005, 09:50:58 PM »
Oh well I tried. (Actualy, I prolly should have waited till I got home to answer. I made my comments as I was shutting down for the day and after I got the computer shut down I realised that my lisp statement was a bit ..."weird".)

But anyways, yeah I get cha now. That is kinda funny. The symbol is destroyed but the reactor is still there. huh?!

Good find Kerry, I'm gonna have to take a look at that some more. (Later though, im tired now.)

Yeah i got one of thos folders too *lol* ...I love those tough ones. They really get my brain going some times.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

dubb

  • Swamp Rat
  • Posts: 1105
Reactors and SDI vs MDI
« Reply #10 on: July 14, 2005, 04:10:47 PM »
Quote from: Jeff_M
Thanks Kerry. No, I hadn't seen that code...and now that I have I think I hurt something, like one of my last remaining brain cells :)

I will continue some testing on this tomorrow.


hows the brain cells doin man..? have we found a solution for this?

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Reactors and SDI vs MDI
« Reply #11 on: July 14, 2005, 07:03:09 PM »
Actually I got busy and forgot about it.... :oops:

Amsterdammed

  • Guest
Reactors and SDI vs MDI
« Reply #12 on: July 16, 2005, 03:32:31 AM »
I might missunderstand something, but there is a function that makes reacors persistent; vlr-pers


Quote
(vlr-pers reactor) Makes a reactor persistent
(vlr-pers-list [reactor]) Returns a list of persistent reactors in the current drawing
(vlr-pers-p reactor) Determines whether or not a reactor is persistent
(vlr-pers-release reactor) Makes a reactor transient


doesn't that do what you want?


Bernd

Columbia

  • Guest
Reactors and SDI vs MDI
« Reply #13 on: July 18, 2005, 11:27:26 AM »
I don't really know why the reactor is remaining persistent in a SDI=1 mode, but the following tips might help with some of the problems.

First...how to distinguish which reactor is yours in a reactor command stack.
In each reactor creation method there is an argument that is normally left 'nil' by a lot of coders, because they don't know what to do with it.  Well here's a nifty idea.  The first argument in the (vlr-editor-reactor) function is a data argument.  In the Acad help files it says to use this argument to attach any LISP code to the argument.  This also means you can attach a string to the reactor object.  You can then READ that string using the (vlr-data) functions passing it an vlr-object.  Do you follow what I'm saying?  Here's an example:
Code: [Select]

(setq jmm_plot_reactor (vlr-Editor-Reactor "Plot Done" '((:vlr-commandEnded . jmm:cmdEnd))))
(vl-data vl-object)
"Plot Done"

Therefore you could loop through the editor reactor objects to find out if one of them is yours -- and pretty simply too.
Code: [Select]

(foreach reactObj (vlr-reactors :VLR-Editor-Reactor)
  (if (= (vlr-data reactObj) "Plot Done")
    (setq found reactObj)
  )
)


Second...It is very, very, VERY important to scrub any non-persistent reactors from your drawing session upon exiting a drawing.  If you don't you get unexpected results, and *gasp* AutoCAD instability.  So here's a small snippet(s) that you will definitely want to add to your code -- the reactor creation one...

Code: [Select]

;; this code creates a drawing reactor that will allow AutoCAD to destroy
;; any and all reactors within a drawing when the drawing recieves a
;; beginclose event.  THIS IS VERY IMPORTANT

(if (not $$_drawing-reactor_$$)
  (setq $$_drawing-reactor_$$
    (vlr-dwg-reactor nil '( (:vlr-beginclose . Remove-Reactors) ))
  )
)

;; the following function scrubs all reactors from a drawing when called.
;; there are two arguments to this function.

(defun Remove-Reactors (calling_reactor_object data_list)
  (mapcar
    'vlr-remove-all
    '(:VLR-AcDb-reactor            :VLR-Editor-reactor
      :VLR-Linker-reactor           :VLR-Object-reactor
      :VLR-Command-Reactor    :VLR-DeepClone-Reactor
      :VLR-DocManager-Reactor :VLR-DWG-Reactor
      :VLR-DXF-Reactor             :VLR-Editor-reactor
      :VLR-Insert-Reactor          :VLR-Linker-Reactor
      :VLR-Lisp-Reactor             :VLR-Miscellaneous-Reactor
      :VLR-Mouse-Reactor          :VLR-Object-Reactor
      :VLR-SysVar-Reactor         :VLR-Toolbar-Reactor
      :VLR-Undo-Reactor            :VLR-Wblock-Reactor
      :VLR-Window-Reactor        :VLR-XREF-Reactor
     )
  )
  (setq jmm_plot_reactor nil)
)


Let me know if this helps out any.