Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Reactor to toggle LTScale between MS/PS

  1. #1
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Lightbulb Reactor to toggle LTScale between MS/PS

    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 04:22 PM.

  2. #2
    Member Steve Doman's Avatar
    Join Date
    2003-12
    Location
    Portland, Oregon USA
    Posts
    13
    Login to Give a bone
    0

    Default Re: Reactor to toggle LTScale between MS/PS

    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. #3
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Reactor to toggle LTScale between MS/PS

    Steve,

    What version(s) of AutoCAD do you need to support?

  4. #4
    Member Steve Doman's Avatar
    Join Date
    2003-12
    Location
    Portland, Oregon USA
    Posts
    13
    Login to Give a bone
    0

    Default Re: Reactor to toggle LTScale between MS/PS

    Robert,

    Thanks for the reply. We are currently running Windows Xp and AutoCAD 2002 (Vanilla). Hope to upgrade to 2k5 soon.

    Steve

  5. #5
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Lightbulb Re: Reactor to toggle LTScale between MS/PS

    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. #6
    Member Steve Doman's Avatar
    Join Date
    2003-12
    Location
    Portland, Oregon USA
    Posts
    13
    Login to Give a bone
    0

    Default Re: Reactor to toggle LTScale between MS/PS

    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. #7
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Reactor to toggle LTScale between MS/PS

    Happy to help. Just reply in the VBA thread if you need any VBA help.

  8. #8
    Member Steve Doman's Avatar
    Join Date
    2003-12
    Location
    Portland, Oregon USA
    Posts
    13
    Login to Give a bone
    0

    Default Re: Reactor to toggle LTScale between MS/PS

    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 08:23 PM.

  9. #9
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Reactor to toggle LTScale between MS/PS

    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 or a user system variable . That way you can change DimScale without affect LTScale. (In case you have large-scale/details on the same sheet.)

    Other than that, I'm glad you found a solution finally.

  10. #10
    Member Steve Doman's Avatar
    Join Date
    2003-12
    Location
    Portland, Oregon USA
    Posts
    13
    Login to Give a bone
    0

    Default Re: Reactor to toggle LTScale between MS/PS

    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!

Page 1 of 2 12 LastLast

Similar Threads

  1. vlr-dwg-reactor issue MY FIRST REACTOR
    By treaves04413213 in forum AutoLISP
    Replies: 21
    Last Post: 2013-10-18, 12:36 PM
  2. Replies: 1
    Last Post: 2009-08-14, 01:05 PM
  3. event reactor for ltscale
    By rolibolibo in forum AutoLISP
    Replies: 2
    Last Post: 2005-07-21, 06:23 PM
  4. Event Handler to toggle LTScale between MS/PS
    By RobertB in forum VBA/COM Interop
    Replies: 0
    Last Post: 2004-06-05, 03:49 AM
  5. Slope Defining Toggle should act like Constrain Toggle
    By gregcashen in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2004-01-15, 10:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •