Reactor when switch between open drawings

Reactor when switch between open drawings

C.Utzinger
Collaborator Collaborator
1,373 Views
11 Replies
Message 1 of 12

Reactor when switch between open drawings

C.Utzinger
Collaborator
Collaborator

HI

 

Is there some kind of Reactor when you are switching between open drawings?

 

I have some Information displayed in MODEMACRO, and I need to execute a routine or load a .lsp when I switch the drawing.

 

 

Please help...

 

Regards

0 Likes
Accepted solutions (2)
1,374 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant

See help HERE

0 Likes
Message 3 of 12

_gile
Consultant
Consultant

Hi,

 

Have a look at vlr-docmanager-reactor.

 

@ВeekeeCZ is still faster than me today.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 12

C.Utzinger
Collaborator
Collaborator

 

OK!

 

I'm a littlebit lost with Callback Functions. The following does not work...

 

 

(defun c:<Test1 ( / )

(defun RTF (calling-reactor commandInfo / dwgname filesize)
  (vl-load-com)
  (setq dwgname (cadr commandInfo)
    filesize (vl-file-size dwgname)
  )
  (alert (strcat "The file size of " dwgname " is "
      (itoa filesize) " bytes."
    )
  )
 (princ)
)

(setq VTFRXNF (vlr-docmanager-reactor nil '((:vlr-documentBecameCurrent   . RTF))))

)

 

Kind regards

0 Likes
Message 5 of 12

ActivistInvestor
Mentor
Mentor
Accepted solution

The documentBecameCurrent notification is going to fire 3 times every time you switch documents (no, I don't know why).

 

You really don't want to do that, but if you insist, the only argument is the AcadDocument com wrapper for the document that's being made current:

 

(vl-load-com)
(vl-load-reactors)

(defun C:TEST()
   (vlr-docmanager-reactor nil
       '((:VLR-documentBecameCurrent . callback)
   )
)

(defun callback (reactor args / fname)
     (setq fname (vla-get-fullname (car args)))
     (if (/= fname "")
         (vla-SetVariable (car args) "MODEMACRO"
             (strcat fname "  " (rtos (vl-file-size fname) 2 0))
         )
     )
)

 

0 Likes
Message 6 of 12

C.Utzinger
Collaborator
Collaborator

 

Thank you, but what is so terrible about this?

 

 

(defun c:<Test1 ( / )

  (vlr-docmanager-reactor nil
      '((:VLR-documentBecameCurrent . callback)))

  (defun callback (reactor args / fname info)
          (setq info (getvar 'MODEMACRO)
                info (if (= (substr info 1 3) "SPI")
                         (vl-string-left-trim " /SPI-:1234567890CMBaselZürichBern" info)
                         info)
                info (vl-string-left-trim " '" info)
                info (if (= info "")
                     (strcat "SPI " *standort* " - 1:" (itoa *mstb*) " / " *einht*)
                     (strcat "SPI " *standort* " - 1:" (itoa *mstb*) " / " *einht* "  '  " info))
          )
          (vla-SetVariable (car args) "MODEMACRO" info)
  )
)

 

Best regards

0 Likes
Message 7 of 12

ActivistInvestor
Mentor
Mentor

@C.Utzinger wrote:

 

Thank you, but what is so terrible about this?

 

 

(defun c:<Test1 ( / )

  (vlr-docmanager-reactor nil
      '((:VLR-documentBecameCurrent . callback)))

  (defun callback (reactor args / fname info)
          (setq info (getvar 'MODEMACRO)
                info (if (= (substr info 1 3) "SPI")
                         (vl-string-left-trim " /SPI-:1234567890CMBaselZürichBern" info)
                         info)
                info (vl-string-left-trim " '" info)
                info (if (= info "")
                     (strcat "SPI " *standort* " - 1:" (itoa *mstb*) " / " *einht*)
                     (strcat "SPI " *standort* " - 1:" (itoa *mstb*) " / " *einht* "  '  " info))
          )
          (vla-SetVariable (car args) "MODEMACRO" info)
  )
)

 

Best regards


What's so terrible about it?  Nothing directly, but did you check to see how many times the callback is fired every time you switch documets?

 

I just don't savor the idea that a callback is being fired 3 times when it should only fire once.

Message 8 of 12

Ranjit_Singh
Advisor
Advisor
Accepted solution

Maybe OP should watch for :vlr-documentToBeActivated event.

0 Likes
Message 9 of 12

ActivistInvestor
Mentor
Mentor

@Ranjit_Singh wrote:

Maybe OP should watch for :vlr-documentToBeActivated event.


Yes he can, because in spite of its name, it actually fires after the document has already been activated.

 

 

Message 10 of 12

C.Utzinger
Collaborator
Collaborator

Good Morning

 

Thank you a lot for the answers.

 

I will use :vlr-documentToBeActivated, it makes what i was looking for.

 

 

Kind regards. 

 

 

How can I include the text from an other comment in my reply, like ActivistInverstor

did in his last comment?

 

 

                         

0 Likes
Message 11 of 12

Ranjit_Singh
Advisor
Advisor

@C.Utzinger wrote:

........

 How can I include the text from an other comment in my reply, like ActivistInverstor

did in his last comment?                      

When replying, look for the QUOTE button and click that.

Message 12 of 12

C.Utzinger
Collaborator
Collaborator

@Ranjit_Singh wrote:

@C.Utzinger wrote:

........

 How can I include the text from an other comment in my reply, like ActivistInverstor

did in his last comment?                      

When replying, look for the QUOTE button and click that.


 

Ahhhh, thank you

0 Likes