clicking in viewport

clicking in viewport

Ranjit_Singh
Advisor Advisor
499 Views
5 Replies
Message 1 of 6

clicking in viewport

Ranjit_Singh
Advisor
Advisor

Can we start a LISP routine by simply clicking in a viewport and not having to call the LISP thru command line. For ex., I am in viewport X and layer 1 is active, and then move to viewport Y and continue annotating, to realize that layer 1 is frozen in viewport Y. Now I have to set layer 2 current.Is there a way for the code to sit in background and then as soon as I click in the viewport call the LISP. I can accoplish the code to set layers based on active viewport. However, I am not sure how to call the LISP simply by clicking in the viewport. Don't know if it is even possible. Thanks.

0 Likes
500 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

I am not experienced in constructing them, nor do I know exactly what kinds of things they can respond to, but I expect a REACTOR could do that -- I hope someone who knows about them can help you, but of course you can read about them in Help and Search here [and elsewhere] for examples.

Kent Cooper, AIA
0 Likes
Message 3 of 6

Ranjit_Singh
Advisor
Advisor

Greet! Atleast now I know the direction to venture in next. I will lookup "reactors" in help. Thanks.

0 Likes
Message 4 of 6

ВeekeeCZ
Consultant
Consultant

Try this quickly modified my only reactor I have... (based on the code made by roy_043 from theswamp.org for me)

 

Spoiler
(defun VPSelected_OnLoad ()
  (if *VPSelected_miscellaneousReactor*
    (vlr-remove *VPSelected_miscellaneousReactor*))
  (setq *VPSelected_miscellaneousReactor* (vlr-miscellaneous-reactor
					    nil
					    '((:vlr-pickfirstmodified . VPSelected_CallBack))))
  (princ "\nVPSelected is running")
)

(defun VPSelected_CallBack (rea lst / ss)
  (if (and (setq ss (cadr (ssgetfirst)))
	   (/= (getvar "CTAB") "Model")
	   (<= (sslength ss) 2)
	   (or (= "VIEWPORT" (cdr (assoc 0 (entget (ssname ss 0)))))
	       (and (= (sslength ss) 2)
		    (= "VIEWPORT" (cdr (assoc 0 (entget (ssname ss 1)))))))
	   )
    (princ "\nMy lisp evoked..."))

)

(VPSelected_OnLoad) ; Starts the reactors.

 

Make your lisp as function and put it instead of the red (princ).

 

To unload reactor run this function:

 

Spoiler
(defun VPSelected_UnLoad ()
  (if *VPSelected_miscellaneousReactor*
    (vlr-remove *VPSelected_miscellaneousReactor*))
  (princ)
)

 

And make some tests and be careful... you know, bad reactor can mess up your AutoCAD really bad. (it runs always you select some object)

0 Likes
Message 5 of 6

Ranjit_Singh
Advisor
Advisor

Thanks BeekeeCZ. I will let you know how it works.

0 Likes
Message 6 of 6

ВeekeeCZ
Consultant
Consultant

@Ranjit_Singh wrote:

... I will let you know how it works.


Let's call it a practice. I read it to quickly... My reactor runs when is selected viewport, not when you step in.. Sorry for false alarm. 🙂

 

 

Then try my second one... I hope with better understanding...

 

Spoiler
; reactor
(defun VPActivated_OnLoad ()
  (if *VPActivated_SysVarReactor*
    (vlr-remove *VPActivated_SysVarReactor*))
  (setq *VPActivated_sysVarReactor* (vlr-sysvar-reactor
				     nil
				     '((:vlr-sysVarChanged . VPActivated_CallBack))))
  (princ "\nVPActivated is running")
)

;callback
(defun VPActivated_CallBack (rea lst /)
  (if (and (= (car lst) "CVPORT")
	   (>= (getvar "CVPORT") 2)
	   )
    (princ "\nMy lisp evoked..."))

)

; load
(VPActivated_OnLoad)




; unload function
(defun c:VPActivated_UnLoad ()
  (if *VPActivated_SysVarReactor*
    (vlr-remove *VPActivated_SysVarReactor*))
  (princ)
)
0 Likes