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))))