Jump to content

Selected Object(s) to Zoom Center within Viewport


rcb007

Recommended Posts

I am trying to put together a routine, where I can select a block or a serval objects and zoom to the center of the overall bounding area through a viewport.

However, I cannot seem to get it working. I hope its something simple. Thank you for checking it out.

 

(defun c:ZoomCenterSelectObject ( /ss )  
(if (setq ss (ssget))
  (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
    (vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)  ;gets LL-LowerLeft and UR-UpperRight of all entitys in selection set
    (setq ptslst (cons (vlax-safearray->list minpt) ptslst)          
          ptslst (cons (vlax-safearray->list maxpt) ptslst)          
    )
  )
)
(setq LL (apply 'mapcar (cons 'min ptslst)) ;calculates the new LL-LowerLeft  from ptslst 
      UR (apply 'mapcar (cons 'max ptslst)) ;calculates the new UR-UpperRight from ptslst
      MPT (mapcar '/ (mapcar '+ LL UR) '(2 2 2)) ;once new LL-LowerLeft and UR-UpperRight are found you can calculate the Mid Point
)  
(command "zoom" "center" MPT "1/50xp") 
(princ))

(c:ZoomCenterSelectObject)

 

Edited by rcb007
Link to comment
Share on other sites

  • rcb007 changed the title to Selected Object(s) to Zoom Center within Viewport

Lee Macs Code above will return coordinates, just need to zoom to them, really easy.

 

Here is anther I use to zoom the viewport to a rectangle (well, a single entity really, could be anything) in the model

 

;;https://forums.autodesk.com/t5/autocad-forum/having-trouble-with-the-lisp-that-zooms-a-rectangle-that-fits-in/td-p/9378532
(defun c:zvprect ( / a b e o)
 (if (setq e (car (entsel "\nSelect Rectangle : ")))
   (progn
     (setq o (vlax-ename->vla-object e))
     (vlax-invoke-method o 'GetBoundingBox 'a 'b)
     (setq a (vlax-safearray->list a)
    b (vlax-safearray->list b)
     )
     (vl-cmdf "_.zoom" a b)
     )
   )
 (princ)
 )

 

Copy 

(vl-cmdf "_.zoom" ls1 ls2)

 

into the end of Lee Macs Code and I reckon combining these 2 you have everything you need

 

or

(vl-cmdf "_.zoom" ll ur)

 

into yours

Edited by Steven P
Link to comment
Share on other sites

In a viewport there is a variable that holds the centre point so can match with Model and nominate a scale as well. This is cut from a bigger program but should give you some ideas. The code makes rectangs the size of the mview in plan at scale matching title block. Then makes multiple layouts.

 

; mp is your point in model space
; ahsc is the scale value for metric it would be say 1:100 = 1000/100 =10
; for imperial like 12 48 96 based on 1 foot

(setq ent (ssname (ssget "x" (list (cons 0  "Viewport")(cons 410 (getvar 'ctab)))) 0))
(setq obj (vlax-ename->vla-object  ent))
(command "mspace")
(command "zoom" "C" mp 500)
(command "zoom" "C" mp (strcat (rtos ahsc 2 1) "XP") )
(command "pspace")
(vla-put-DisplayLocked obj  -1)

 

  • Like 1
Link to comment
Share on other sites

Interesting you mentioned this. You use the word nominate a scale. Would it be possible to "auto scale" the viewports? 

Once objects are in the viewport, it would automatically adjust to whatever scale it would be closest too. 

If the objects were scaled slightly below a 1"=50' it would then auto adjust to that 1"=50'. I would assume that the scale factor would always round up.

Or if the scale is halfway between 1"-40' and 1'=50'; that would round up to the 1"=50'.

Again, this just an idea. Not sure it is logical or not.

Link to comment
Share on other sites

This link might help: (https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/changing-viewport-scale-via-lisp/td-p/1753210#:~:text=Some%20clues...%20%3B%3B%3Bto%20get%20the%20scale%20of%20the,VP_SC%20%28%2F%201%20%28vla-get-customscale%20%28vlax-ename-%3Evla-object%20%28ssname%20SS%200%29%29%29%29%29)

 

: (setq SS (ssget "X" (list '(0 . "VIEWPORT")(cons 410 (getvar "ctab")))))
(setq acounbt 0) ; a count marker for below, can use it to loop through the selection set

:;get the scale of the first viewport in the selection set
 (setq VP_SC (/ 1 (vla-get-customscale (vlax-ename->vla-object (ssname SS acount)))))

: ;set the scale of the first viewport in the selection set
 (vla-put-customscale (vlax-ename->vla-object (ssname SS acounbt)) (/ 1 48.0))

 

Where you have a selection set in your example, you can create a loop

 

If you create a list of your standard scales - this can vary depending where you are and the work you do in order then you can comp[are your scale to each item in this list stopping when you get to a point where you get the righty scale. Have a go an I'll look back later to help if you are stuck

Link to comment
Share on other sites

I would go the other way as I mentioned, our layouts had a fixed title block so a Mview size was always known, this can be retranslated to a rectang in model space, so guess if rectang is to small go to next scale, could be a dcl with 3 options smaller bigger and OK. Yes using your scales. Note the angle change in the rectangs the auto layouts follow the rectang angle.

 

layout1.png.9d03ab6cd7fbd5b4a128c15fbe0c31bf.png

The advantage is copy, move, rotate then make layouts.

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...