rkent Posted October 11, 2018 Share Posted October 11, 2018 I have looked at this lisp file for a while and don't understand it well enough to make the change I am after. I would like for it to toggle between CURSORSIZE 100 and CURSORTYPE 0 when in the functions defined by the reactor. And then go back to CURSORTYPE 1 when done. ;;;Tip# 3936 By Mathew Kirkland from Cadalyst.com (vl-load-com) ;;;------------------------------------------------------------------ --; ;;; List of commands to react to: ;;; Note - This string will be used in a wcmatch statement. (setq *CursorSize_Commands* "COPY,ERASE,GRIP_STRETCH,PLOT,MLEADER,MEASUREGEOM,MOVE,SCALE,STRETCH") ;;;------------------------------------------------------------------ --; ;;; Start reactor function: (defun c:CursorSizeOn () (CursorSize:StartReactor)) ;;;------------------------------------------------------------------ --; ;;; Stop reactor function: (defun c:CursorSizeOff () (vlr-remove *CursorSize_CommandReactor*) (terpri) (prompt "\n** CursorSize reactor has been stopped ** ") (princ)) ;;;------------------------------------------------------------------ --; ;;; Start reactor function: (defun CursorSize:StartReactor () ;; Command reactors (or *CursorSize_CommandReactor* (setq *CursorSize_CommandReactor* (vlr-command-reactor nil '((:vlr-commandCancelled . CursorSize:CommandEnded) (:vlr-commandEnded . CursorSize:CommandEnded) (:vlr-commandFailed . CursorSize:CommandEnded) (:vlr-commandWillStart . CursorSize:CommandWillStart))))) ;; <- Other reactors (prompt "\n \n >> CursorSize reactor loaded ") (princ)) ;;;------------------------------------------------------------------ --; ;;; CursorSize:CommandWillStart callback function: (defun CursorSize:CommandWillStart (rea cmd / cmdName) (cond ((and (/= "" *CursorSize_Commands*) (wcmatch (setq cmdName (car cmd)) *CursorSize_Commands*)) (setq *CursorSize* (getvar 'cursorsize)) (setvar 'cursorsize 100)) ;; <- Other conditions ) ) ;;;------------------------------------------------------------------ --; ;;; CursorSize:CommandEnded callback function: (defun CursorSize:CommandEnded (rea cmd / cmdName) (cond ((and (/= "" *CursorSize_Commands*) (wcmatch (setq cmdName (car cmd)) *CursorSize_Commands*)) (setvar 'cursorsize *CursorSize*) (setq *CursorSize* nil)) ;; <- Other conditions ) ) ;;;------------------------------------------------------------------ --; (c:CursorSizeOn) (princ) Thanks for any help with this request. rkent Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 11, 2018 Share Posted October 11, 2018 Try this quick slight modification: "I would like for it to toggle between CURSORSIZE 100 and CURSORTYPE 0 when in the functions defined by the reactor. And then go back to CURSORTYPE 1 when done" "https://www.cadtutor.net/forum/topic/66200-need-lisp-file-modified-to-toggle-cursor-type/" ;;;Tip# 3936 By Mathew Kirkland from Cadalyst.com (vl-load-com) ;;;------------------------------------------------------------------ --; ;;; List of commands to react to: ;;; Note - This string will be used in a wcmatch statement. (setq *CursorSize_Commands* "COPY,ERASE,GRIP_STRETCH,PLOT,MLEADER,MEASUREGEOM,MOVE,SCALE,STRETCH") ;;;------------------------------------------------------------------ --; ;;; Start reactor function: (defun c:CursorSizeOn () (setvar 'cursortype 1) (CursorSize:StartReactor) ) ;;;------------------------------------------------------------------ --; ;;; Stop reactor function: (defun c:CursorSizeOff () (vlr-remove *CursorSize_CommandReactor*) (terpri) (prompt "\n** CursorSize reactor has been stopped ** ") (princ) ) ;;;------------------------------------------------------------------ --; ;;; Start reactor function: (defun CursorSize:StartReactor () ;; Command reactors (or *CursorSize_CommandReactor* (setq *CursorSize_CommandReactor* (vlr-command-reactor nil '((:vlr-commandCancelled . CursorSize:CommandEnded) (:vlr-commandEnded . CursorSize:CommandEnded) (:vlr-commandFailed . CursorSize:CommandEnded) (:vlr-commandWillStart . CursorSize:CommandWillStart) ) ) ) ) ;; <- Other reactors (prompt "\n \n >> CursorSize reactor loaded ") (princ) ) ;;;------------------------------------------------------------------ --; ;;; CursorSize:CommandWillStart callback function: (defun CursorSize:CommandWillStart (rea cmd / cmdName) (cond ( (and (/= "" *CursorSize_Commands*) (wcmatch (setq cmdName (car cmd)) *CursorSize_Commands*) ) (setq *CursorSizeNtype* (mapcar 'getvar '(cursorsize cursortype))) (mapcar 'setvar '(cursorsize cursortype) '(100 0)) ) ;; <- Other conditions ) ) ;;;------------------------------------------------------------------ --; ;;; CursorSize:CommandEnded callback function: (defun CursorSize:CommandEnded (rea cmd / cmdName) (cond ( (and (/= "" *CursorSize_Commands*) (wcmatch (setq cmdName (car cmd)) *CursorSize_Commands*) ) (mapcar 'setvar '(cursorsize cursortype) *CursorSizeNtype*) (setq *CursorSizeNtype* nil) ) ;; <- Other conditions ) ) ;;;------------------------------------------------------------------ Quote Link to comment Share on other sites More sharing options...
rkent Posted October 11, 2018 Author Share Posted October 11, 2018 Thank you Grrr, that is working great. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 11, 2018 Share Posted October 11, 2018 (edited) I wrote the following code some time ago, but the forum was unresponsive - nevertheless, try the following: (setq cursorreactor:com "COPY,ERASE,GRIP_STRETCH,PLOT,MLEADER,MEASUREGEOM,MOVE,SCALE,STRETCH" cursorreactor:sys '((cursorsize 100) (cursortype 0)) cursorreactor:key "cursorreactor" ) (defun c:cursorreactoron ( ) (cursorreactor:enable cursorreactor:key) (princ "\nCursor reactor enabled.") (princ) ) (defun c:cursorreactoroff ( ) (cursorreactor:cb2 nil nil) (cursorreactor:disable cursorreactor:key) (princ "\nCursor reactor disabled.") (princ) ) (defun cursorreactor:enable ( key ) (cursorreactor:disable key) (vlr-set-notification (vlr-command-reactor key '( (:vlr-commandwillstart . cursorreactor:cb1) (:vlr-commandended . cursorreactor:cb2) (:vlr-commandcancelled . cursorreactor:cb2) (:vlr-commandfailed . cursorreactor:cb2) ) ) 'active-document-only ) ) (defun cursorreactor:disable ( key ) (foreach rtr (cdar (vlr-reactors :vlr-command-reactor)) (if (= key (vlr-data rtr)) (vlr-remove rtr) ) ) ) (defun cursorreactor:cb1 ( rtr arg / val ) (if (and arg (wcmatch (strcase (car arg)) cursorreactor:com)) (progn (cursorreactor:cb2 nil nil) (foreach var cursorreactor:sys (if (setq val (getvar (car var))) (progn (setq cursorreactor:val (cons (list (car var) val) cursorreactor:val)) (apply 'setvar var) ) ) ) ) ) (princ) ) (defun cursorreactor:cb2 ( rtr arg ) (if cursorreactor:val (progn (foreach var cursorreactor:val (apply 'setvar var)) (setq cursorreactor:val nil) ) ) (princ) ) (vl-load-com) (princ) Edited October 11, 2018 by Lee Mac Quote Link to comment Share on other sites More sharing options...
rkent Posted October 11, 2018 Author Share Posted October 11, 2018 Works very well Lee, thank you. Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 11, 2018 Share Posted October 11, 2018 Hi Lee, Just a small tip - you could reduce the code with a single callback function, by utilising the vlr-current-reaction-name function and some conditional aswell. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 11, 2018 Share Posted October 11, 2018 2 hours ago, Grrr said: Just a small tip - you could reduce the code with a single callback function, by utilising the vlr-current-reaction-name function and some conditional aswell. Maybe I'm missing something, but I don't see the advantage of this approach? This would be less efficient as there would be an additional test expression required to determine the correct course of action whenever a callback function is evaluated. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 11, 2018 Share Posted October 11, 2018 3 hours ago, rkent said: Works very well Lee, thank you. You're welcome @rkent - the list of system variables & values located at the top of the code may be expanded to suit your requirements. Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 11, 2018 Share Posted October 11, 2018 1 hour ago, Lee Mac said: This would be less efficient as there would be an additional test expression required to determine the correct course of action whenever a callback function is evaluated I thought about mentioning the same - but stripped that sentence off, because I'm not sure whats more inefficient: a test expression or a pointer to the other callback function. Quote Link to comment Share on other sites More sharing options...
amarcon Posted October 14, 2018 Share Posted October 14, 2018 Lee, Thank you, grabbing your routine as I can see it can be very useful for some tasks. Never knew it could be done so efficiently. Thanks OP for querying the great minds in this forum Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.