Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: How can I recognize when switching between drawings with a reactor?

  1. #1
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default How can I recognize when switching between drawings with a reactor?

    I have tried this code with no luck

    The test function will never be trigged
    Code:
    (defun Function_When_Switching_Drawing (ObjArg ListArg / )
      (alert "Drawing Switched" )
    )
    The reactor
    Code:
    (setq Switching_Drawing_REACTOR (vlr-docmanager-reactor '((:vlr-documentToBeActivated . Function_When_Switching_Drawing ))) )
    (setq Switching_Drawing_REACTOR2 (vlr-docmanager-reactor '((:vlr-documentToBeDeactivated . Function_When_Switching_Drawing ))) )
    To remove the reactor and function
    Code:
    (vlr-remove Switching_Drawing_REACTOR )
    (setq Function_When_Switching_Drawing nil Switching_Drawing_REACTOR nil )
    : ) kennet

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: How can I recognize when switching between drawings with a reactor?

    Aren't you missing a part of the reactor call? I thought there were at least two arguments required for reactors.
    Code:
    (setq Switching_Drawing_REACTOR (vlr-docmanager-reactor nil '((:vlr-documentToBeActivated . Function_When_Switching_Drawing ))) )
    You also may not want to do both of those reactors. I went into an endless loop and had to close down AutoCAD.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: How can I recognize when switching between drawings with a reactor?

    I generally add some form of identification (instead of nil) to the reactor declaration. That way I don't need a global variable, to hold the reference to the reactor, in order to remove it.

    Someting like (vlr-docmanager-reactor "Check DWG Switch" .....).

    Then I also add some code just before declaring it, something like:
    Code:
    ;; Clear reactors
    (setq rlst (vlr-reactors))
    (foreach item rlst
      (foreach ro (cdr item)
        (if (= "Check DWG Switch" (vlr-data ro))
          (vlr-remove ro)
        ) ;_ end of if
      ) ;_ end of foreach
    ) ;_ end of foreach
    Otherwise you may be loading that LSP again & have the reactor firing twice. This is usually the case while debugging, but may also happen if the LSP is loaded in 2 places.

  4. #4
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: How can I recognize when switching between drawings with a reactor?

    Yes Opie, the nil argument is missed in the forum ( both lines ), but I misspelled in a different way in my code, sorry for taking your time. Thank you anyway and. . .

    : ) Happy Computing !

    kennet

  5. #5
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: How can I recognize when switching between drawings with a reactor?

    Quote Originally Posted by Opie View Post
    Aren't you missing a part of the reactor call? I thought there were at least two arguments required for reactors.
    Code:
    (setq Switching_Drawing_REACTOR (vlr-docmanager-reactor nil '((:vlr-documentToBeActivated . Function_When_Switching_Drawing ))) )
    You also may not want to do both of those reactors. I went into an endless loop and had to close down AutoCAD.
    I think it goes into an endless loop with only one of the reactors.

    I need some assistance that is right up this program's alley. I am trying to add some extra measures to keep Eagle Point (EP) in line (it's our third party civil software) We would like to be able to use MDI (some of us do already) but I dont want the users to necessarily be concerned with making sure they switch between drawings using the Eagle Point interface. I found which registry key is modified when EP switches between drawings, so I figured I would write a lisp that will automatically change the registry key if the user switches to the drawing via AutoCAD (that way EP doesnt freak out.) I have the program written (as far as I know), but I need help on the reactor to get it to run.

    Code:
    (defun epcdchange ()
      (if
        (and
          (or
    	(wcmatch (strcase (vl-filename-base (getvar "dwgname")))
    		 "RCP#####,RC######,RCPRF###,RCT#####,RCXSC###,SSHY####,STHY####"
    	) ;_ end of wcmatch
    	(vl-file-systime (strcat (getvar "dwgprefix") (vl-filename-base (getvar "dwgname")) ".set"))
          ) ;_ end of or
          (= (vl-registry-read
    	   "HKEY_CURRENT_USER\\Software\\Eagle Point Software\\egpt\\EP\\"
    	   "CurrentDataLocation"
    	 ) ;_ end of vl-registry-read
    	 (getvar "dwgprefix")
          ) ;_ end of =
        ) ;_ end of and
         (vl-registry-write
           "HKEY_CURRENT_USER\\Software\\Eagle Point Software\\egpt\\EP\\"
           "CurrentDrawing"
           (strcat (getvar "dwgprefix") (getvar "dwgname"))
         ) ;_ end of vl-registry-write
      ) ;_ end of if
    ) ;_ end of defun
    Any suggestions would be appreciated (if you think this is a bad idea please let me know why)

    Thanks,
    Last edited by ccowgill; 2009-08-20 at 06:43 PM. Reason: Added code

  6. #6
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: How can I recognize when switching between drawings with a reactor?

    Christopher,

    You probably need two reactors, one for activation and one for deactivation.

    For the activation, check to see if a global variable is set. If it is not set, assign it any value then run your code. If it is set, it means you have already run your code so do not run your code again.

    For the deactivation, set the global variable to nil. This will allow the activation code to work when you get back in to a EP project drawing.

    I'll have to check your code tomorrow (if I have time) to see how it works with EP. I could possibly use this as well.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  7. #7
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: How can I recognize when switching between drawings with a reactor?

    Quote Originally Posted by Opie View Post
    Christopher,

    You probably need two reactors, one for activation and one for deactivation.

    For the activation, check to see if a global variable is set. If it is not set, assign it any value then run your code. If it is set, it means you have already run your code so do not run your code again.

    For the deactivation, set the global variable to nil. This will allow the activation code to work when you get back in to a EP project drawing.

    I'll have to check your code tomorrow (if I have time) to see how it works with EP. I could possibly use this as well.
    It is way too early in the morning, I dont have a clue what you are referring to. Any chance you can provide an example? I tried using the tobeactivated reactor and it seemed to throw AutoCAD into an infinite loop. Then I tried a documentbecamecurrent reactor, but it appears to be firing multiple times and I dont have a clue how to get around it.

  8. #8
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: How can I recognize when switching between drawings with a reactor?

    In your routine that is called based on the reactor for activation (renamed here from epcdchange), add an if statement
    Code:
    (defun WJ:EPToBeActivated (ObjArg ListArg) ;To use in a reactor, you need two arguments added to your code
      (if (not blnFlag)
        (progn
          (setq blnFlag t)
          Do the rest of your command...
        )
      )
    )
    Create another routine for the deactivation
    Code:
    (defun WJ:EPToBeDeactivated (ObjArg ListArg)
      (if blnFlag
        (setq blnFlag nil)
      )
    )
    Then add your reactor for activation
    Code:
    (vlr-docmanager-reactor
      "WJ:EPToBeActivated"
      '((:vlr-documentToBeActivated . WJ:EPToBeActivated))
    )
    And one for deactivation
    Code:
    (vlr-docmanager-reactor
      "WJ:EPToBeDeactivated"
      '((:vlr-documentToBeDeactivated . WJ:EPToBeDeactivated))
    )
    And using irneb's code for removal of the reactors
    Code:
    (setq rlst (vlr-reactors))
    (foreach item rlst
      (foreach ro (cdr item)
        (if (member (vlr-data ro) '("WJ:EPToBeActivated" "WJ:EPToBeActivated"))
          (vlr-remove ro)
        )
      )
    )
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  9. #9
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: How can I recognize when switching between drawings with a reactor?

    ok, rewording it the way I understand it, Create a reactor that fires when the drawing becomes activated, the program will have a flag that will only allow it to run once, even if the reactor fires multiple times. Then when the drawing is deactivated, it will reset the flag to nil so that the next time the drawing is activated the program will run once. correct?
    We house all of our reactor's in the same file, and they call to other functions, that way it reduces the likelihood that a reactor will be loaded more than once. Here is what I have for a portion of my reactor file:
    Code:
    (if (not Activating_Drawing_Reactor)
      (setq	Activating_Drawing_Reactor
    	 (vlr-docmanager-reactor
    	   "WJ:EPToBeActivated"
    	   '((:vlr-documenttobeactivated
    	      .
    	      WJ:EPToBeActivated
    	     )
    	    )
    	 ) ;_ end of vlr-docmanager-reactor
      ) ;_ end of setq
      () ;_ the reactor is already loaded
    ) ;_ end of if
    (if (not Deactivating_Drawing_Reactor)
      (setq	Deactivating_Drawing_Reactor
    	 (vlr-docmanager-reactor
    	   "WJ:EPToBeDeactivated"
    	   '((:vlr-documenttobedeactivated
    	      .
    	      WJ:EPToBeDeactivated
    	     )
    	    )
    	 ) ;_ end of vlr-docmanager-reactor
      ) ;_ end of setq
      () ;_ the reactor is already loaded
    ) ;_ end of if
    
    (defun WJ:EPToBeActivated (In_ReactorName In_Command /)
      (if (not blnFlag)
        (progn
          (setq blnFlag t)
          (epcdchange)
          )
        )
    ) ;_ end of defun
    (defun WJ:EPToBeDeactivated (In_ReactorName In_Command /)
      (if blnFlag
          (setq blnFlag nil)
        )
    ) ;_ end of defun
    the lisp for EPCDchange is already loaded in the drawing.
    Last edited by ccowgill; 2009-08-21 at 01:37 PM. Reason: added code

  10. #10
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: How can I recognize when switching between drawings with a reactor?

    Correct. Also, everytime AutoCAD loses focus, the deactivation reactor will fire and everytime it regains focus, the activation reactor will fire.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Page 1 of 3 123 LastLast

Similar Threads

  1. 2011: Switching layouts switches drawings
    By msanders.236848 in forum AutoCAD General
    Replies: 2
    Last Post: 2011-12-12, 12:48 PM
  2. 2011: Trouble Switching Between Drawings
    By msanders.236848 in forum AutoCAD General
    Replies: 10
    Last Post: 2011-06-15, 04:32 PM
  3. 2011: Switching between Drawings
    By mhannan.100562 in forum ACA General
    Replies: 6
    Last Post: 2011-03-07, 01:52 PM
  4. 2009 slow switching between drawings
    By dzatto in forum ACA General
    Replies: 4
    Last Post: 2010-02-18, 03:31 PM
  5. Delay when switching between drawings
    By westcad in forum ACA General
    Replies: 1
    Last Post: 2007-06-15, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •