;; MVALIGN.LSP Copyright 1991-1997 Tony Tanzillo all rights reserved. ;; ;; This program was originally published in the Tips and Tricks ;; column of CADENCE Magazine in 1994, and is the sole property ;; of Tony Tanzillo, Design Automation Consulting. ;; ;; MVALIGN command ;; ;; Aligns (registers) views in two or more model space viewports. ;; ;; This command is convenient when you need to construct a non- ;; rectanguar view that is composed of two or more model space ;; viewports which are laid out in a tiled fashion, where view ;; registration is required (e.g., the views in each of the ;; viewports must be aligned such that they appear as a single ;; contiguous view, when viewport borders are made invisible). ;; ;; When TILEMODE is OFF, invoke MVALIGN, and select the viewport ;; with the defining view (the one that is to remain fixed with ;; respect to the other views). Then select all viewports whose ;; views are to be aligned with the defining viewport's view. ;; ;; The view direction in each viewport must be parallel to each ;; other and the view direction of the defining view, and all of ;; the views to be aligned must be turned on. ;; ;; Remember where you saw it first. (defun C:MVALIGN ( / vp1 cvport vpset vplist e i) (cond ( (not (zerop (getvar "tilemode"))) (princ "\n*** Command not allowed unless TILEMODE is set to 0.")) ( (progn (setvar "cmdecho" 0) (command "._undo" "_g") (setq cvport (getvar "cvport")) (cond ( (> cvport 1) (princ "\n*** Switching to paper space ***") (command ".PSPACE"))) nil ) ) ( (not (setq vp1 (car (entsel "\nSelect defining viewport: "))))) ( (not (eq "VIEWPORT" (cdr (assoc 0 (entget vp1))))) (princ "\nInvalid, selected object is not a viewport.")) ( (progn (princ "\nSelect target viewports,") nil)) ( (not (setq vpset (ssget '( (-4 . "") (68 . 0) (-4 . "and>"))))) (princ "\nNothing selected.")) ( (and (eq 1 (sslength vpset)) (ssmemb vp1 vpset)) (princ "\nDefining viewport ignored, nothing selected.")) ( (progn (repeat (setq i (sslength vpset)) (if (not (eq vp1 (setq e (ssname vpset (setq i (1- i)))))) (setq vplist (append vplist (list e))))) (not vplist))) (t (setq i (mvalign (cons vp1 vplist))) (cond ( (eq cvport 1) (command ".pspace")) (t (setvar "cvport" cvport))) (command "._undo" "_e") (cond (i (princ (strcat "\nAligned " (itoa i) " viewports."))) (t (princ "\nNo viewports were aligned."))) ) ) (princ) ) ; -------------------------------------------------------------------------- ; Function: MVALIGN ; ; (mvalign ) ; ; Back-end for C:MVALIGN ; ; is a list of entity names of viewports to be aligned. ; ; The first viewport in is the defining viewport whose ; current view is the one to which all other views are aligned to. ; ; All viewports whose views are to be aligned must have the same ; view direction. (defun mvalign (vplist / cvport vp1 vp1xd vp1d pscen1 xpfact mscen1 viewdir vp2d pscen2 psang msdist xpscale i) (setq cvport (getvar "cvport")) (if (eq 1 (getvar "cvport")) (command ".mspace") ) (setq vp1 (car vplist) vp1xd (entxdata vp1 "acad") vp1d (entget vp1) vp1id (cdr (assoc 69 vp1d)) pscen1 (cdr (assoc 10 vp1d)) xpfact (/ (cdr (assoc 41 vp1d)) (cdr (nth 6 vp1xd))) xpscale (/ 1.0 xpfact) mscen1 (list (cdr (nth 7 vp1xd)) (cdr (nth 8 vp1xd))) ) (setvar "cvport" (cdr (assoc 69 vp1d))) (setq viewdir (getvar "viewdir")) (setq i 0) (foreach vp2 (cdr vplist) (cond ( (and (/= vp1 vp2) (setq vp2d (entget vp2)) (eq "VIEWPORT" (cdr (assoc 0 vp2d))) (not (zerop (cdr (assoc 68 vp2d)))) (progn (setvar "cvport" (cdr (assoc 69 vp2d))) (equal viewdir (getvar "viewdir")))) (setq pscen2 (cdr (assoc 10 vp2d)) psang (angle pscen1 pscen2) msdist (* xpscale (distance pscen1 pscen2)) i (1+ i) ) (command ".zoom" "c" (polar mscen1 psang msdist) (/ (cdr (assoc 41 vp2d)) xpfact) ) ) ) ) (cond ( (zerop i) nil) (t i)) ) ; -------------------------------------------------------------------------- ; Function: ENTXDATA ; ; (entxdata ) ; ; Retrieves extended data attached to an entity for a given APPID. (defun entxdata (ent appid / d) (if (and (setq d (entget ent (list appid))) (setq d (assoc -3 d)) (cdadr d)) (cdadr d)) ) ;; END MVALIGN.LSP