;;----------------------=={ Selection Counter }==----------------------;;
;; ;;
;; A very short & simple snippet of code to automatically display the ;;
;; number of objects in the active selection in the status bar. ;;
;; ;;
;; The selection reactor will be enabled on loading by default, but ;;
;; may be subsequently enabled or disabled manually using the ;;
;; SELCOUNTON & SELCOUNTOFF commands respectively. ;;
;;----------------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2014 - http://www.lee-mac.com ;;
;;----------------------------------------------------------------------;;
;; Version 1.0 - 2014-11-13 ;;
;; ;;
;; First release. ;;
;;----------------------------------------------------------------------;;
;; Version 1.1 - 2014-11-15 ;;
;; ;;
;; Program modified to fix bug when using the UNDO command. ;;
;;----------------------------------------------------------------------;;

(defun c:selcounton nil
(selcount:remove)
(vlr-miscellaneous-reactor "selcount" '((:vlr-pickfirstmodified . selcount:callback)))
(vlr-command-reactor "selcount" '((:vlr-commandwillstart . selcount:undostart) (:vlr-commandended . selcount:undoended)))
(princ "\nSelection Counter enabled.")
(princ)
)
(defun c:selcountoff nil
(selcount:remove)
(princ "\nSelection Counter disabled.")
(princ)
)
(defun selcount:remove nil
(foreach obj (apply 'append (mapcar 'cdr (vlr-reactors :vlr-miscellaneous-reactor :vlr-command-reactor)))
(if (= "selcount" (vlr-data obj)) (vlr-remove obj))
)
)
(defun selcount:callback ( obj arg / int sel )
(if (and (setq sel (cadr (ssgetfirst))) (< 0 (setq int (sslength sel))))
(progn
(if (null selcount:modemacro)
(setq selcount:modemacro (getvar 'modemacro))
)
(setvar 'modemacro (strcat (itoa int) " object" (if (= 1 int) "" "s") " selected."))
)
(progn
(if (= 'str (type selcount:modemacro))
(setvar 'modemacro selcount:modemacro)
)
(setq selcount:modemacro nil)
)
)
(princ)
)
(defun selcount:undostart ( obj arg )
(if (wcmatch (strcase (car arg)) "U,UNDO")
(setq selcount:undomodemacro (getvar 'modemacro))
)
(princ)
)
(defun selcount:undoended ( obj arg )
(if (= 'str (type selcount:undomodemacro))
(progn
(setvar 'modemacro selcount:undomodemacro)
(setq selcount:undomodemacro nil)
)
)
(princ)
)
(vl-load-com) (c:selcounton)

;;----------------------------------------------------------------------;;
;; End of File ;;
;;----------------------------------------------------------------------;;

Advertisements