Jump to content

need lisp file modified to toggle cursor type


rkent

Recommended Posts

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...