Author Topic: Zoom out to fit an object into screen  (Read 7076 times)

0 Members and 1 Guest are viewing this topic.

iliekater

  • Guest
Zoom out to fit an object into screen
« on: December 17, 2007, 01:02:27 AM »
Is it possiple to zoom out in order to make a specific object fit whole into the screen ?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Zoom out to fit an object into screen
« Reply #1 on: December 17, 2007, 01:55:28 AM »
Yes, look at the object bounding-box which sets variables for the lower left and upper-right .. then zoom window using those 2 points.

this may help ;
Code: [Select]
(defun ObjectMidPoint (activeXObject / p1 p2)
   (vla-getboundingbox activeXObject 'p1 'p2)
   (setq p1 (vlax-safearray->list p1)
         p2 (vlax-safearray->list p2)
   )
   (mapcar '* '(0.5 0.5 0.5)(mapcar '+ p1 p2))
)

P1 and P2 are the box corners for your Zoom Command ..


« Last Edit: December 17, 2007, 02:07:03 AM by Kerry Brown »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

gile

  • Water Moccasin
  • Posts: 2221
  • Marseille, France
Re: Zoom out to fit an object into screen
« Reply #2 on: December 17, 2007, 02:29:32 AM »
Hi,

If your ACAD version allows it, you can use the the option "object" of ZOOM command: (vl-cmdf "_.zoom" "_o" (ssget) "")

If it don't or if you'd rather not using command, I wrote a ZoomObject routine (cause vla-ZoomObject isn't provided)

Code: [Select]
;; ZoomObject
;; Zoom on objects countained in a list
;;
;; Argument
;; objlst : a vla-objects list
;;
;; Variables
;; dir : normal vector of the current view plane
;; ang : Twist angle of the current view
;; 3x3 : 3x3 transformation matrix fron WCS to current view
;; 4x4 : 4x4 transformation matrix fron WCS to current view
;; ptlst : list of all min and max points of objects bounding boxes

(defun ZoomObject (objlst / dir ang 3x3 4x4 ptlst)
  (vl-load-com)
  (setq dir (trans '(0 0 1) 2 0 T)
ang (- (getvar "viewtwist"))
3x3 (mxm (mapcar '(lambda (x) (trans x 0 dir))
'((1 0 0) (0 1 0) (0 0 1))
)
(list (list (cos ang) (- (sin ang)) 0)
       (list (sin ang) (cos ang) 0)
       '(0 0 1)
)
    )
4x4 (append
      (mapcar
'(lambda (v o)
   (append v (list o))
)
3x3
'(0 0 0)
      )
      (list '(0 0 0 1))
    )
  )
  (foreach obj objlst
    (vla-TransformBy obj (vlax-tmatrix (trp 4x4)))
    (vla-getBoundingBox obj 'minpt 'maxpt)
    (vla-TransformBy obj (vlax-tmatrix 4x4))
    (setq ptlst (cons (vlax-safearray->list minpt)
      (cons (vlax-safearray->list maxpt) ptlst)
)
    )
  )
  (vla-ZoomWindow
    (vlax-get-acad-object)
    (vlax-3d-point (mxv 3x3 (apply 'mapcar (cons 'min ptlst))))
    (vlax-3d-point (mxv 3x3 (apply 'mapcar (cons 'max ptlst))))
  )
)

;; transpose a matrix by Doug Wilson

(defun trp (m)
  (apply 'mapcar (cons 'list m))
)

;; Apply a transformation matrix to a vector by Vladimir Nesterovsky

(defun mxv (m v)
  (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m)
)

;; Multiply two matrices by Vladimir Nesterovsky

(defun mxm (m q)
  (mapcar '(lambda (r) (mxv (trp q) r)) m)
)

A test/calling function:

Code: [Select]
(defun c:zo (/ lst)
  (vl-load-com)
  (or *acdoc*
      (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  )
  (if
    (ssget)
     (progn
       (vla-StartUndoMark *acdoc*)
       (ZoomObject
(vlax-for o (vla-get-ActiveSelectionSet *acdoc*)
   (setq lst (cons o lst))
)
       )
       (vla-EndUndoMark *acdoc*)
     )
  )
  (princ)
)
« Last Edit: December 17, 2007, 03:47:23 AM by gile »
Speaking English as a French Frog

GDF

  • Water Moccasin
  • Posts: 1982
Re: Zoom out to fit an object into screen
« Reply #3 on: December 17, 2007, 10:45:49 AM »
Gile, nice routine.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

gile

  • Water Moccasin
  • Posts: 2221
  • Marseille, France
Re: Zoom out to fit an object into screen
« Reply #4 on: December 17, 2007, 11:58:17 AM »
Thanks, Gary.
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12227
  • London, England
Re: Zoom out to fit an object into screen
« Reply #5 on: September 21, 2009, 05:26:42 AM »
Very nice Gile -

While I can follow the matrix calculations, I wouldn't have been able to come up with it myself...  :lol:

hermanm

  • Bull Frog
  • Posts: 282
Re: Zoom out to fit an object into screen
« Reply #6 on: September 21, 2009, 10:10:43 AM »
Nice job, Gile. :)

I use this for one entity:

Code: [Select]
;;zoom to an object
;;accept ename or vla-object
(defun zoom-to (obj / lowleft upright)
  (if (eq (type obj) 'ENAME) (setq obj (vlax-ename->vla-object obj)))
  (vla-getboundingbox obj 'lowleft 'upright)
  (vlax-invoke-method (vlax-get-acad-object) 'zoomwindow lowleft upright)
)
If you don't know where you are going, you might not get there.
  - L.P. Berra

xiaxiang

  • Guest
Re: Zoom out to fit an object into screen
« Reply #7 on: January 15, 2013, 02:34:59 AM »
Hi,all.
Gile,Nice stuff.
My question is that who know the "zoom" method when using DBX?
As you know,command "zoom" is not permitted,and either vla-ZoomWindow or
vla-ZoomExtents is not permitted.
irneb,if you can see this topic...
Is there any way to change the properties of viewport to comply "zoom" function?
as follow topic
zoom extend the all opened drawings cadtutor
http://www.cadtutor.net/forum/showthread.php?55925-zoom-extend-the-all-opened-drawings
Maybe it's Impossible task,but I research for several days.
Many thanks!