|
Welcome, Guest.
|
||||||
| AutoLISP AutoLISP or Visual LISP, learn both here! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Administrator
Join Date: 2001-08
Location: Seattle WA US
Posts: 4,393
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
This code should serve only as a simple boilerplate (perhaps placed in Acad.lsp) to give you a start in making a reactor that toggles LTScale when you switch from ModelSpace to a Layout.
It makes the assumption that the current DimScale is the scale factor you want for ModelSpace. This is a poor assumption IMHO, but you can decide how you want to store the scale factor yourself. (I might suggest a Dictionary/XRecord.) Also, I perform no Regens, so the effects won't be visible until you do so. Code:
(defun I:ChangedLayout (reactor layout)
(setvar "LTScale"
(* 0.5
(cond ((/= (strcase (car layout)) "MODEL") 1)
((zerop (getvar "DimScale")) 1)
((getvar "DimScale"))))))
(cond ((not *LayoutLTS*)
(setq *LayoutLTS* (vlr-Miscellaneous-Reactor
nil
'((:vlr-LayoutSwitched . I:ChangedLayout))))))
Last edited by RobertB : 2004-06-04 at 06:22 PM. |
|
|
|
|
|
#2 |
|
Member
Join Date: 2003-12
Location: Portland, Oregon USA
Posts: 13
![]() |
Hi Robert,
I like the idea of using a LTScale reactor to automatically change Ltscale when changing from Model space to PaperSpace and have experimeted with several versions. However I find that with all versions I've tried including the code you posted, none regen the drawing after changing the Ltscale. From the users standpoint, having to manually enter the Regen command after switching layouts makes having a LTS reactor only slightly beneficial. I've tried modifying these reactors to include a regen by adding a (vla-regen *doc* acActiveViewport) just before the reactor callback function ends. This however crashes AutoCAD bigtime! So to my point, do you know of a way to automatically cause a regen after changing layouts. I tried setting "Regenerate the drawing each time you switch tabs" from the options command, but that seems to cause a regen before the reactor callback runs. Any ideas Obi-Wan? Thanks, Steve Doman |
|
|
|
|
|
#3 |
|
Administrator
Join Date: 2001-08
Location: Seattle WA US
Posts: 4,393
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Steve,
What version(s) of AutoCAD do you need to support? |
|
|
|
|
|
#4 |
|
Member
Join Date: 2003-12
Location: Portland, Oregon USA
Posts: 13
![]() |
Robert,
Thanks for the reply. We are currently running Windows Xp and AutoCAD 2002 (Vanilla). Hope to upgrade to 2k5 soon. Steve |
|
|
|
|
|
#5 |
|
Administrator
Join Date: 2001-08
Location: Seattle WA US
Posts: 4,393
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Steve,
Actually, to be honest, I hate Visual LISP's reactors (shh, don't tell anyone). I far prefer to use VBA Events where possible. Please see this code for a VBA example of the same approach. This VBA code does the regen, but I have only tested in 2004/2005. Seems to me it worked in 2002, but the memory is fading. |
|
|
|
|
|
#6 |
|
Member
Join Date: 2003-12
Location: Portland, Oregon USA
Posts: 13
![]() |
Oh my gosh, VBA? I have no experience with VBA, but can understand the code you posted. So I guess now is a good time to learn a little VB, seeing as I have to figure out how to load it!
I'll do some testing with A2k2 on Monday. My home PC isn't setup for AutoCAD at the moment. Thanks for the help and I'll get back with you on how things worked. Thanks a billion, Steve Doman |
|
|
|
|
|
#7 |
|
Administrator
Join Date: 2001-08
Location: Seattle WA US
Posts: 4,393
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Happy to help. Just reply in the VBA thread if you need any VBA help.
|
|
|
|
|
|
#8 |
|
Member
Join Date: 2003-12
Location: Portland, Oregon USA
Posts: 13
![]() |
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
Last edited by sdoman : 2004-07-25 at 10:23 PM. |
|
|
|
|
|
#9 |
|
Administrator
Join Date: 2001-08
Location: Seattle WA US
Posts: 4,393
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Steve,
Once again, I'd like to point out that basing this reactor on DimScale is, IMHO, a bad idea. Far better to store the "primary scale factor" in an XRecord Other than that, I'm glad you found a solution finally. |
|
|
|
|
|
#10 |
|
Member
Join Date: 2003-12
Location: Portland, Oregon USA
Posts: 13
![]() |
Well to each their own. I like having the Dimscale control the LTScale and don't really understand why you would want a "primary scale factor" other than Dimscale.
Having a correlation between Dimscale and LTScale seems very natural and intuitive to how drawings are created, were I work anyway. This reactor gizmo allows us to be free of maintaining the optimum LTScale while edititing and plotting. Also too, having this gives us a different way to think about the drawing process, in that you would set Dimscale before you draw or edit the object, rather then aftwards when ready to dimension. In drawings which contain many differently scaled Viewports, the user simply changes the Dimscale when editing that particular area. Thanks! |
|
|
|
![]() |
|
||||||
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Visibility Toggle | bclarch | Revit Architecture "Original" Wish List (Archived) | 16 | 2006-06-21 06:51 PM |
| Slope Defining Toggle should act like Constrain Toggle | gregcashen | Revit Architecture "Original" Wish List (Archived) | 0 | 2004-01-15 11:17 PM |