Resize viewport

Resize viewport

msarqui
Collaborator Collaborator
1,572 Views
2 Replies
Message 1 of 3

Resize viewport

msarqui
Collaborator
Collaborator

Hi everyone!

Is it possible to resize a paper space viewport to match the corners of a rectangle in model space with lisp?

Let's say that in an active viewport, I set the scale, I draw a rectangle, I select this rectangle and then the viewport resizes to its corners?

Thanks

Marcelo

0 Likes
Accepted solutions (1)
1,573 Views
2 Replies
Replies (2)
Message 2 of 3

Ranjit_Singh
Advisor
Advisor
Accepted solution

For example, see below. Tested only for a very simple case. See screencast.

(defun c:somefunc  (/ csc curcv etdata h ls pt1 vp w)
 (cond ((= 1 (getvar 'tilemode)) (print "Need to be in layout tab") (exit))
       (t
	(command "._pspace")
	(setq vp  (car (entsel "\nSelect Viewport: "))
	      ls  (getpropertyvalue vp "Locked")
	      csc (getpropertyvalue vp "CustomScale"))
	(setpropertyvalue vp "Locked" 0)
	(command "._mspace")
	(setq etdata (mapcar 'cdr
			     (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget (car (entsel "\nSelect rectangle: ")))))
	      pt1    (mapcar '(lambda (x y) (/ (+ x y) 2.0)) (car etdata) (caddr etdata))
	      w	     (abs (- (caar etdata) (caaddr etdata)))
	      h	     (abs (- (cadar etdata) (car (cdaddr etdata)))))
	(mapcar	'(lambda (x y) (setpropertyvalue vp x y))
		'("ViewCenter/X" "ViewCenter/y" "Height" "Width" "CustomScale" "Locked")
		(list (car pt1) (cadr pt1) (* h csc) (* w csc) csc ls))
	(command "._pspace")
	(princ))))
0 Likes
Message 3 of 3

msarqui
Collaborator
Collaborator
This is awesome!
Thanks Ranjit.Singh
0 Likes