Results 1 to 6 of 6

Thread: Autolisp*: Change INSUNITS when switching from layout mode to model space

  1. #1
    Member
    Join Date
    2011-11
    Posts
    4
    Login to Give a bone
    0

    Default Autolisp*: Change INSUNITS when switching from layout mode to model space

    Working in metric, our base unit is sometimes millimetres (structural, mechanical) and sometimes metres (civil).

    Our border blocks including drawing frames, title blocks, north arrows and other symbols, are designed in millimetres. When we're in tilemode 1 model space working in metres, and have to go to the layout to add a symbol or update a title block, we usually forget to change INSUNITS to millimetres, and likewise often forget to change it back when we go back to model space.

    I'm looking for a way to change INSUNITS when we change space via the Model/Layout tabs. Is there anything out there that does this? (It doesn't have to change if we double-click into a viewport to model space as we don't do any drafting there anyway.)

    *(sorry, doing this wrong, don't see a prefix dropdown)

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Autolisp*: Change INSUNITS when switching from layout mode to model space

    Sounds like that would create serious issues with linetype scales and lineweights as well. Scaling those border blocks would be one solution. Xrefing in the (structural, mechanical) drawings to scale would be another.

    Doing Civil work we get Architectural drawings from outside and xref them in to scale no problem.

  3. #3
    Member
    Join Date
    2011-11
    Posts
    4
    Login to Give a bone
    0

    Default Re: Autolisp*: Change INSUNITS when switching from layout mode to model space

    It doesn't create a problem with linetypes and lineweights - not sure why it would. Everything in model space is in metres, what's in paper space is in millimetres.

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Autolisp*: Change INSUNITS when switching from layout mode to model space

    Welcome to AUGI.


    Based on what I was able to glean from your OP, give this a try:

    Basically, this starts a Command Reactor that will determine which space you are in by evaluating the CVPORT sysvar, and sets both the INSUNITS, and MODEMACRO sysvar accordingly. I've preemptively used the Meters & Millimeters values here, but others can simply change the red values to suite their own work as needed.

    Code:
    (vl-load-com)
    
    ;;;--------------------------------------------------------------------;
    ;;; Start reactor function:
    (defun UnitsReactor:Start ()
    
      ;; Command reactors
      (or *UnitsReactors_Command*
          (setq *UnitsReactors_Command*
                 (vlr-command-reactor
                   nil
                   '(
                     (:vlr-commandCancelled . UnitsReactor:SetUnitsOnCommand)
                     (:vlr-commandEnded . UnitsReactor:SetUnitsOnCommand)
                     (:vlr-commandFailed . UnitsReactor:SetUnitsOnCommand)
                     (:vlr-commandWillStart . UnitsReactor:SetUnitsOnCommand)
                    )
                 )
          )
      )
      (prompt "\nUnits reactor started. ")
      (princ)
    )
    ;;;--------------------------------------------------------------------;
    ;;; UnitsReactor:SetMessage function:
    (defun UnitsReactor:SetMessage (insunits / msg modemacro i)
      (setq msg
             (strcat
               "INSUNITS: "
               (cond
                 ((= 0 insunits) "Unitless")
                 ((= 1 insunits) "Inches")
                 ((= 2 insunits) "Feet")
                 ((= 3 insunits) "Miles")
                 ((= 4 insunits) "Millimeters")
                 ((= 5 insunits) "Centimeters")
                 ((= 6 insunits) "Meters")
                 ((= 7 insunits) "Kilometers")
                 ((= 8 insunits) "Microinches")
                 ((= 9 insunits) "Mils")
                 ((= 10 insunits) "Yards")
                 ((= 11 insunits) "Angstroms")
                 ((= 12 insunits) "Nanometers")
                 ((= 13 insunits) "Microns")
                 ((= 14 insunits) "Decimeters")
                 ((= 15 insunits) "Dekameters")
                 ((= 16 insunits) "Hectometers")
                 ((= 17 insunits) "Gigameters")
                 ((= 18 insunits) "Astronomical Units")
                 ((= 19 insunits) "Light Years")
                 ((= 20 insunits) "Parsecs")
               )
               " | "
             )
      )
      (if
        (setq i
               (vl-string-search "| " (setq modemacro (getvar 'modemacro)))
        )
         (setvar 'modemacro
                 (vl-string-subst msg (substr modemacro 1 (+ 2 i)) modemacro)
         )
         (setvar 'modemacro (strcat msg modemacro))
      )
      (princ)
    )
    ;;;--------------------------------------------------------------------;
    ;;; UnitsReactor:SetUnitsOnCommand callback function:
    (defun UnitsReactor:SetUnitsOnCommand (rea cmd)
      (UnitsReactor:SetMessage
        (setvar 'insunits
                (if (= 1 (getvar 'cvport))
                  4                                                         ; paper, millimeters
                  6                                                         ; model, or active viewport, meters
                )
        )
      )
    )
    ;;;--------------------------------------------------------------------;
    ;;; Stop reactor function:
    (defun c:StopUnitsReactor ()
    
      ;; Command reactors
      (if *UnitsReactors_Command*
        (progn
          (vlr-remove *UnitsReactors_Command*)
          (setq *UnitsReactors_Command* nil)
        )
      )
      (setvar 'modemacro "")
      (prompt "\n** Units reactor stopped. **")
      (princ)
    )
    ;;;--------------------------------------------------------------------;
    ;;; autorun at load:
    (UnitsReactor:Start)


    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Member
    Join Date
    2011-11
    Posts
    4
    Login to Give a bone
    0

    Default Re: Autolisp*: Change INSUNITS when switching from layout mode to model space

    Awesome! Thanks Blackbox!

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Autolisp*: Change INSUNITS when switching from layout mode to model space

    Quote Originally Posted by dmbyrnes122575 View Post
    Awesome! Thanks Blackbox!
    You're welcome, dmbyrnes122575; I'm glad you found it useful.


    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. 2016: switching back to model space
    By rmk in forum AutoCAD Civil 3D - General
    Replies: 3
    Last Post: 2016-02-12, 04:26 PM
  2. Layer Frozen/Off Status in Model Space/Layout Space
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2013-01-17, 04:29 AM
  3. why do i get NOT RESPONDING when switching to model space?
    By cadman33619 in forum AutoCAD General
    Replies: 5
    Last Post: 2012-05-22, 03:11 AM
  4. Replies: 0
    Last Post: 2011-10-21, 06:44 PM
  5. Replies: 0
    Last Post: 2010-04-01, 03:21 PM

Tags for this Thread

Posting Permissions

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