I had a little time to play with AutoCAD 2005 today and experimented with adding a vla-regen to the LTScale reactor code you posted. Worked great! No crashes! So I ran with the code you posted and embellish it a bit.
It seems to me that the user would want the LTScale to automatically change when the layout changes form Model to Paper space, *and* whenever the Dimscale changes. So I threw in another reactor that watches for the dimscale to change.
In addition, I thought this LTS reactor should be user friendly and have some kind off method for the user to turn the LTS reactor off or on. So I threw in a c:function to toggle the reactor.
Here's what I got so far, based on your core reactor code. Note the warning:
Code:
;|
*** Warning ***
Note that the following code might/will crash AutoCAD unless
you are running release 16+
|;
(vl-load-com)
(defun c:AutoLTS (/ on off status prmpt answer *error*)
;;
;; User command to turn AutoLTS on or off
;;
(defun *error* (msg)
(cond
((member
msg
'("Function cancelled" "quit / exit abort" "console break")
)
)
((princ (strcat " Error: " msg)))
)
(princ)
)
;;
(setq on "1"
off "0"
)
(if *LayoutLTS*
(setq status on)
(setq status off)
)
(setq prmpt (strcat "\nEnter new value for AutoLTS <" status ">: "))
(initget (strcat on " " off))
(setq answer (getkword prmpt))
(cond ((not answer) nil) ;_<Enter> key
((and (= answer off) (= status on))
(vlr-remove *LayoutLTS*)
(vlr-remove *DimscaleLTS*)
(setq *LayoutLTS* nil
*DimscaleLTS* nil
)
)
((and (= answer on) (= status off)) (I:AutoLTS))
)
(princ)
)
(defun I:ChangedLayout (reactor layout)
;;
;; Calculate and set the LTScale
;; Regenall
;;
(setvar "LTScale"
(* 0.5
(cond ((/= (strcase (car layout)) "MODEL") 1)
((zerop (getvar "DimScale")) 1)
((getvar "DimScale"))
)
)
)
;;
;; *** WARNING ***
;; Prior to release 16, the following
;; line may crash AutoCAD hard
;;
(vla-regen
(vla-get-activedocument (vlax-get-acad-object))
acAllViewports
)
)
(defun I:ChangedDimscale (reactor info)
;;
;; If changed sysvar is Dimscale
;; Call ChangedLayout function
;; Otherwise ignore
;;
(cond ((= (strcase (car info)) "DIMSCALE")
(I:ChangedLayout
nil
(list (vla-get-name
(vla-get-activelayout
(vla-get-activedocument
(vlax-get-acad-object)
)
)
)
)
)
)
)
)
(defun I:AutoLTS ()
;;
;; Function to create two reactors
;;
;; One reactor calls I:ChangedLayout function
;; whenever the layout changes
;;
;; The other reactor calls the I:ChangedDimscale
;; function whenever the Dimscale changes.
;;
(if (not *DimscaleLTS*)
(setq *DimscaleLTS*
(vlr-sysvar-reactor
nil
'((:vlr-sysvarchanged . I:ChangedDimscale))
)
)
)
(if (not *LayoutLTS*)
(setq *LayoutLTS*
(vlr-Miscellaneous-Reactor
nil
'((:vlr-LayoutSwitched . I:ChangedLayout))
)
)
)
)
;; eof