Rotating your view without changing coordinate values


OR  aka DVIEW TWIST and SNAPANG.  There isn’t a building or subdivision i’ve ever done that looks good with north straight up. Typically, north has to be rotated somewhat to get the view we’re looking for. You know something like this.

To do that with AutoCAD, you need to use two commands – DVIEW and SNAPANG.  Dview has many uses, most of which I have no clue. But what it can do is rotate your view without changing the coordinate values. Snapang is used to set the crosshairs horizontal by using the negative angle of the twisted view.  Blah, blah, blah….

Well, it came across twitter last night that someone was looking for the easy/lazy way to do this.  I have a solution. Simply because I was also looking for a lazy way to do this, but like 15 years ago.  Someone, somewhere in the discussion groups posted a lsp code that did this very thing.

To use it, load it like any other lsp file.  The command to run it is TW.  It will ask for two points to pick, left to right, to set as the horizontal base.  The osnap is changed to nearest during the command and then reset to its condition prior to the command. Once you’ve picked two points, the view rotates and the crosshairs are horizontal.  Now, for us, we use a sheet grid reference file so we not only know the angle but also the view scale for setting sheets.  This is helpful even in reference files to get the perspective you’re after.  No need to remember the angle, simply refer to the, um, reference file.

The command also gives you an option to enter an angle if you choose. Sometimes this is helpful is you simply want to go back to true north, or enter ZERO.

There is a secondary command, SNAG, that you can use.  So let’s say you’re in a sheet file with a few layouts. As you set and recall views for each viewport, the VIEW command does not adjust the crosshairs. SNAG grabs the view angle and sets it horizontal. Piece o cake.

Honestly, I’m not sure why these aren’t built into at least the civil flavored apps. That would make most of this effort that much more transparent.

Hope this helps!

Here’s a quick video:

Here’s the code: (change file extension from .doc to .lsp) TW_SNAG

;****************************************************************************
; -----TWST----- DVIEW TWIST & SNAP ANG
;****************************************************************************

;;;  LISP  uses two points or an input angle to
;;;    twist the current view using the the dview command.
;;;    the snapangle variable is reset to make the cursor
;;;    appear horizontal.

;;;;The dtr funtion converts degrees to radians
;;;;The rtd funtion converts radians to degrees

(defun RTD (/ANG) (/ (* ANG 180.0) pi))

(defun DTR (/ANG) (* pi (/ ANG 180.0)))

(defun C:TW (/ P1 P2 ANG)
;;;  store the cmdecho, osnapcoord, osmode and orhtomode system varibles
  (setq CE-SAV (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq OSCOORD-SAV (getvar "osnapcoord"))
  (setvar "osnapcoord" 1)
  (setq OSMODE-SAV (getvar "osmode"))
  (setvar "osmode" 512)
  (setq ORTHOMODE-SAV (getvar "orthomode"))
  (setvar "orthomode" 0)
  (princ
    "\nTwist view and cursor angle by picking two point or entering an angle
"
  )					; _ end ofPRINC
  (if (setq P2 (getpoint
		 "\nFirst point(left) <Press Enter to input an angle>: "
	       )			; _ end of GETPOINT
      ) ;_ end of SETQ
    (progn (initget 1)
	   (setq P1  (getpoint "\nSecond point(right): " P2)
		 ANG (angle P2 P1)
	   ) ;_ end of SETQ
	   (command "DVIEW" "L" "" "TW" (- 360 (RTD ANG)) "")
	   (setvar "SNAPANG" ANG)
    ) ;_  end of PROGN
    (progn (setq ANG (getangle "\nAngle: "))
	   (command "DVIEW" "L" "" "TW" (- 360 (RTD ANG)) "")
	   (setvar "SNAPANG" ANG)
    ) ;_ end of PROGN
  ) ;_  end of IF
  (setvar "cmdecho" CE-SAV)
  (setvar "osnapcoord" OSCOORD-SAV)
  (setvar "OSMODE" OSMODE-SAV)
  (setvar "orthomode" ORTHOMODE-SAV)
;;; print the rotation angle to the screen:  converts string to local units
  and
  precision
  (princ
    (strcat "\nTwist angle: "
	    (angtos ANG (getvar "aunits") (getvar "auprec"))
    ) ;_ end of strcat
  ) ;_ end of princ
  (princ)
) ;_  end of DEFUN

;****************************************************************************
; -----SNAG----- SET SNAP ANG TO DVIEW TWIST
;****************************************************************************

(defun c:snag (/ VANG SANG)
  (setq VANG (getvar "viewtwist"))
  (setq SANG (- (* 2 pi) VANG))
  (setvar "snapang" SANG)
  !
)
Advertisements

About Kevin
Hi… I am a husband, father, brother and neighbor. I am employed as a Civil Engineer and have enjoyed playing the drums for the last 30+ years.

7 Responses to Rotating your view without changing coordinate values

  1. Very interesting post thank you for that bit of information, I had know Idea that you could also do that with the command set you posted

    Like

  2. surdraft says:

    Hi Kevin,
    Thanks for the great post. Really helpful. I haven’t tried the lisp routine yet, just used in the type commands and it did the job. I used MVSETUP for twisting my viewports.as I couldn’t quite understand what you meant about the VIEW command. Were you doing that in model space or layout space?
    Would you recommend VIEW over MVSETUP? or even something else?
    Either way I now have a drawing twisted the way I wanted, thanks again for your helpful post.

    Mitch
    http://www.surdraft.com

    Like

    • Kevin says:

      Mitch, the VIEW command is used to save a particular view. “When you save specific views by name, you can restore them for layout and plotting or when you need to refer to specific details. A named view created with the VIEW command consists of a specific magnification, position, and orientation.”

      For my taste, MVSETUP was more for a mechanical set of views, but could certainly also be used for site engineering as well i suppose. That is the both the beauty and pain of Autocad; yet another way to do the same thing. 🙂

      Like

      • surdraft says:

        Ha!
        Being an AutoCAD newbie compared to some of our esteemed colleagues out in the webisphere, I am researching how to do something at least once a week. So I know the feeling! I often get swamped with options, and its a struggle not to jumble them all up creating some combined-command-catastrophe sending my drawing into the realms of no return!
        Cheers for the clarification on the VIEW command. Sounds like a pretty handy tool that I’ll do my best to incorporate soon. If i don’t I invariably forget the command exists!

        Like

  3. surdraft says:

    Oh, and cheers for the quick reply. 🙂

    Like

  4. Christopher says:

    I’m going to have to install this on my computer. Did you know Caltrans is using this lisp. I did not until today.

    Like

    • Kevin says:

      No i did not. I found this several years ago in the forums. So I cannot claim anything other than paying it forward. 🙂 Do you know how they found it?

      Kevin

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: