Jump to content
rkent

need lisp file modified to toggle cursor type

Recommended Posts

rkent

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

Share this post


Link to post
Share on other sites
Grrr

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
  )
)
;;;------------------------------------------------------------------

 

Share this post


Link to post
Share on other sites
rkent

Thank you Grrr, that is working great.

Share this post


Link to post
Share on other sites
Lee Mac

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 by Lee Mac

Share this post


Link to post
Share on other sites
rkent

Works very well Lee, thank you.

Share this post


Link to post
Share on other sites
Grrr

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.

Share this post


Link to post
Share on other sites
Lee Mac
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.

Share this post


Link to post
Share on other sites
Lee Mac
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.

Share this post


Link to post
Share on other sites
Grrr
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.

Share this post


Link to post
Share on other sites
amarcon

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 ;)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×