;;; Rotate View in paperspace
;;; Written By Clark Johnson - Toromont Energy Systems, Inc.
;;; Concept from Cadalyst Tips & Tools Weekly - Sept. 15, 2008 - http://www.cadalyst.com
;;; Modified by Igal Averbuh 2019 (added option to set the view angle specified by two points)

(defun c:rv (/ sset DPL DPLS vprt a1 a2)
(setvar "cmdecho" 0)
(command "pspace");;move to paperspace
(princ "\nSelect Viewport to rotate...")
(setq sset(ssget ":s" '((0 . "viewport"))));;Select viewport
(setq DPL (vlax-ename->vla-object (ssname sset 0)));;Get viewport name
(setq DPLS (vlax-get-property DPL "DisplayLocked"));;Get Locked Status for Viewport
(vla-put-DisplayLocked DPL :vlax-true);; LOCK Viewport
(setq vprt(cdr(assoc 69 (entget(ssname sset 0)))))
(command "._mspace")
(princ "\Select view rotation angle by 2 points on screen")

(setq P1 (getpoint "\nEnter First Point :"))
(setq P2 (getpoint P1 "\nSecond Point :"))
(vla-put-DisplayLocked DPL :vlax-false);; UNLOCK Viewport

;(setq a1 (getangle "\nEnter or Select rotation angle..."));;Get Rotation Angle
;(setq a2 (* a1 57.29578))

(command "mspace");;move to modelspace
(command "cvport" vprt);;Get selected viewport

(command "DVIEW" "" "TW" (/ (* -180 (angle P1 P2)) pi) "")

(command "pspace");;Return to paperspace
(vla-put-DisplayLocked DPL :vlax-true)
;(vla-put-DisplayLocked DPL DPLS);;; Restore Locked Status for Viewport
(setvar "cmdecho" 1)