I'm having trouble with the following Lisp routine. It works fine in 2004, but has a problem in 2006.
Essentially, it tells you the current scale of a viewport, and lets you change it if you wish. You can run it in floating model space, in which case it works on the current viewport, or in paper space, in which case you select one or more viewports, and it cycles through them.
The issue is on 2006, when multiple viewports are selected. The routine works fine up until the user tries to enter a new viewport scale. Then Autocad crashes hard, as soon as the first keystroke happens. No need to hit return or anything; just hit any key, and Autocad will take a dump.
I tried debugging the routine, but I noticed that if I first start the VLISP editor, then load the Lisp while the VLISP editor is active, I have no issues. The routine works fine. The key is that the Lisp routine must be loaded while the VLISP editor is open. I can open the VLISP editor, load VPS.LISP, and close the VLISP editor, and the routine will work fine. However, if the VLISP editor is not open when the routine is loaded, Autocad crashes on an unhandled exception error during user input.
This gave me an idea, so I tried turning off Dynamic Input. Sure enough, the routine works without a problem. So, running this Lisp in 2006 with Dynamic Input enabled causes Autocad to crash hard on an unhandled exception error. I have no idea why - I think it's a bug inside Autocad somewhere. It could have something to do with the way the Lisp routine shifts the active viewport, interacting badly with Dynamic Input.
I'm planning on submitting a bug report to Autodesk. Can anyone verify this bug, or maybe provide some insight as to why the crash is occurring, or any other input that I can also pass on to Autodesk in the bug report?
; vps.lsp v1.01
; Richard Sincovec Sep-18-2004
; Displays currently-active paperspace viewport scale in decimal/metric
; form, and lets user specify a new one. If user is in paperspace
; instead of floating modelspace, multiple viewports can be selected.
; (Command does nothing in modelspace.)
(vl-load-com)
(defun vps:scaleViewport (doc vp / cscale sctxt inp)
(vla-highlight vp :vlax-true)
(setq cscale (vla-get-customScale vp)
sctxt (cond
((> cscale 1)
(strcat (cond
((equal cscale (fix cscale) 0.01)
(rtos cscale 2 0)
)
((rtos cscale 2 2))
) ;_ cond
":1"
) ;_ strcat
)
((setq cscale (/ 1 cscale))
(strcat
"1:"
(cond
((equal cscale (fix cscale) 0.01)
(rtos cscale 2 0)
)
((rtos cscale 2 2))
) ;_ cond
) ;_ strcat
)
) ;_ cond
inp (getreal
(strcat "\nCurrent scale "
sctxt
"; new scale? "
) ;_ strcat
) ;_ getreal
) ;_ setq
(vla-highlight vp :vlax-false)
(if inp
(vla-put-customScale vp inp)
(vla-put-activePViewport doc vp)
) ;_ if
) ;_ defun
(defun c:vps (/ ss err index count doc vp)
(if (= (getvar "tilemode") 1)
(princ "VPS only works in paperspace!")
(if (= (getvar "cvport") 1)
;; in paperspace
(progn
(setq err
(vl-catch-all-apply
(function
(lambda ()
(setq ss (ssget '((0 . "VIEWPORT")))
count (sslength ss)
index -1
) ;_ setq
(while (< (setq index (1+ index)) count)
(setq vp (vlax-ename->vla-object (ssname ss index))
doc (vla-get-document vp)
) ;_ setq
(vla-display vp :vlax-true)
(vla-put-mspace doc :vlax-true)
(vla-put-activePViewport doc vp)
(vps:scaleViewport doc vp)
) ;_ while
) ;_ lambda
) ;_ function
) ;_ vl-catch-all-apply
) ;_ setq
(vla-put-mspace doc :vlax-false)
) ;_ progn
;; in floating modelspace
(setq err
(vl-catch-all-apply
(function
(lambda ()
(setq doc (vla-get-activeDocument (vlax-get-acad-object))
vp (vla-get-activePViewport doc)
) ;_ setq
(vps:scaleViewport doc vp)
(vla-regen doc acActiveViewport)
) ;_ lambda
) ;_ function
) ;_ vl-catch-all-apply
) ;_ setq
) ;_ if
) ;_ if
(if (vl-catch-all-error-p err)
(princ (vl-catch-all-error-message err))
) ;_ if
(princ)
) ;_ defun