Pan all Viewports in selected Layouts

Pan all Viewports in selected Layouts

jtm2020hyo
Collaborator Collaborator
5,492 Views
13 Replies
Message 1 of 14

Pan all Viewports in selected Layouts

jtm2020hyo
Collaborator
Collaborator

I need to select multiple layouts and enter a code to PAN  all viewports in the typed coordinates

 

example:

 

*Layout1:

  2 viewports, the first viewing
*Layout2:

  3 viewports, one 

*Layout1 (1): (this is a copy)

  2 viewports,

*Layout2 (1): (this is a copy)

  3 viewports, one 

 

So I need to pan all viewports from Layout1 (1) and Layout2 (1) 1000 units to axis Y (x:0,y:1000,z=0)

 

image.pngimage.png

 

 

 

 

So I want to request to create an LSP, VBA, FAS or any routine to pan all viewports from selected layouts to any typed coordinates. 

 

I found nothing like this in google.

0 Likes
Accepted solutions (2)
5,493 Views
13 Replies
Replies (13)
Message 2 of 14

Sea-Haven
Mentor
Mentor

1st don’t you mean move the viewports.

 

ok if you get extmin extmax this is the corner points of the viewports. So just use these with move and window option using the 2corners then the new point co-ords

Message 3 of 14

jtm2020hyo
Collaborator
Collaborator

@Sea-Haven wrote:

1st don’t you mean move the viewports.

 

ok if you get extmin extmax this is the corner points of the viewports. So just use these with move and window option using the 2corners then the new point co-ords


 

thanks for your help.

I will try to explain better what I need because of my bad English

 

example, I need to move viewports like this:

____________________________________

*Layout1:

  2 viewports, target view (red 1) and (red 2)


*Layout2:

  3 viewports,  target view (red 3) (red 4) and (red 5)

 

*"Layout1 (1)": (this is a copy of Layout1)

  2 viewports, target view (red 1) and (red 2))

 

*"Layout2 (1)": (this is a copy of Layout2)

3 viewports,  target view (red 3) (red 4) and (red 5)

______________________________________

 

I need to pan all viewports ,from "Layout1 (2)" and "Layout2 (2)" , 6558.8231 units to axis Y (x:0,y:6558.8231,z=0)

like this:

 

____________________________________

*Layout1:

  2 viewports, target view (red 1) and (red 2)


*Layout2:

  3 viewports,  target view (red 3) (red 4) and (red 5)

 

*"Layout1 (2)": (this is a copy of Layout1)

  2 viewports, target view (white 1) and (white 2)

 

*"Layout2 (2)": (this is a copy of Layout2)

  3 viewports, target view (white 3) (white 4) and (white 5)

______________________________________

 

here images to a better explaining (square red and white are viewport projections):

 

image.pngimage.pngimage.pngimage.pngimage.png

===================================================

 

 

So I need a routine (VBA or LSP or FAS or anything) to "-PAN" ( X:0, Y:6558.8231, Z:0, in the example) all viewports in selected LAYOUTS ("Layout1 (2)" and "Layout2 (2)" in the example)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 4 of 14

marko_ribar
Advisor
Advisor

Go to Paper Space... Step into desired viewport by double clicking inside... Grab variable (setq ce (getvar 'viewctr))... Calculate new ce variable as (setq ce (mapcar '+ ce '(0.0 6558.8231 0.0)))... Grab variable (setq vs (getvar 'viewsize))...

Finally, instead of PAN command, use (vl-cmdf "_.zoom" "_c" "_non" ce vs)... Repeat process for all viewports and in all desired Layouts... Automate procedure into *.lsp file, so that you can do it automatically, just by selecting desired viewport... I hope it is clear... Now go to CAD and finish your job as required...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 5 of 14

jtm2020hyo
Collaborator
Collaborator

@marko_ribar wrote:

Go to Paper Space... Step into desired viewport by double clicking inside... Grab variable (setq ce (getvar 'viewctr))... Calculate new ce variable as (setq ce (mapcar '+ ce '(0.0 6558.8231 0.0)))... Grab variable (setq vs (getvar 'viewsize))...

Finally, instead of PAN command, use (vl-cmdf "_.zoom" "_c" "_non" ce vs)... Repeat process for all viewports and in all desired Layouts... Automate procedure into *.lsp file, so that you can do it automatically, just by selecting desired viewport... I hope it is clear... Now go to CAD and finish your job as required...


I need to do this to 500 layouts.
it is possible to do this without joining Layouts?

I just need selected LAYOUT tabs with Ctrl-key and clicking and do that process with a command line.

0 Likes
Message 6 of 14

marko_ribar
Advisor
Advisor

Here is for single viewport :

 

(defun c:processviewport ( / *error* *adoc* s vp ce vs cenew )

  (vl-load-com)

  (defun *error* ( m )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (while
    (or
      (prompt "\nPick VIEWPORT entity to activate...")
      (not (setq s (ssget "_+.:E:S:L" '((0 . "VIEWPORT") (-4 . "<not") (410 . "Model") (-4 . "not>")))))
    )
    (prompt "\nMissed or picked wrong entity type...")
  )
  (setq vp (ssname s 0))
  (vla-display (vlax-ename->vla-object vp) :vlax-true)
  (vla-put-mspace *adoc* :vlax-true)
  (vla-put-activepviewport *adoc* (vlax-ename->vla-object vp))
  (setq ce (getvar 'viewctr))
  (setq vs (getvar 'viewsize))
  (setq cenew (mapcar '+ ce '(0.0 6558.8231 0.0)))
  (vl-cmdf "_.zoom" "_c" "_non" cenew vs)
  (vla-put-mspace *adoc* :vlax-false)
  (*error* nil)
)

And here is for all viewports in all layouts...

 

(defun c:processviewportsinalllayouts ( / *error* *adoc* ct ss i vp ce vs cenew )

  (vl-load-com)

  (defun *error* ( m )
    (if ct
      (setvar 'ctab ct)
    )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (setq ct (getvar 'ctab))
  (foreach lay (layoutlist)
    (setvar 'ctab lay)
    (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 lay))))
    (repeat (setq i (sslength ss))
      (setq vp (ssname ss (setq i (1- i))))
      (vla-display (vlax-ename->vla-object vp) :vlax-true)
      (vla-put-mspace *adoc* :vlax-true)
      (vl-catch-all-apply 'vla-put-activepviewport (list *adoc* (vlax-ename->vla-object vp)))
      (setq ce (getvar 'viewctr))
      (setq vs (getvar 'viewsize))
      (setq cenew (mapcar '+ ce '(0.0 6558.8231 0.0)))
      (vl-cmdf "_.zoom" "_c" "_non" cenew vs)
      (vla-put-mspace *adoc* :vlax-false)
    )
  )
  (*error* nil)
)

HTH., M.R.

Cheers...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 7 of 14

jtm2020hyo
Collaborator
Collaborator

@marko_ribar wrote:

Here is for single viewport :

 

(defun c:processviewport ( / *error* *adoc* s vp ce vs cenew )

  (vl-load-com)

  (defun *error* ( m )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (while
    (or
      (prompt "\nPick VIEWPORT entity to activate...")
      (not (setq s (ssget "_+.:E:S:L" '((0 . "VIEWPORT") (-4 . "<not") (410 . "Model") (-4 . "not>")))))
    )
    (prompt "\nMissed or picked wrong entity type...")
  )
  (setq vp (ssname s 0))
  (vla-display (vlax-ename->vla-object vp) :vlax-true)
  (vla-put-mspace *adoc* :vlax-true)
  (vla-put-activepviewport *adoc* (vlax-ename->vla-object vp))
  (setq ce (getvar 'viewctr))
  (setq vs (getvar 'viewsize))
  (setq cenew (mapcar '+ ce '(0.0 6558.8231 0.0)))
  (vl-cmdf "_.zoom" "_c" "_non" cenew vs)
  (vla-put-mspace *adoc* :vlax-false)
  (*error* nil)
)

And here is for all viewports in all layouts...

 

(defun c:processviewportsinalllayouts ( / *error* *adoc* ct ss i vp ce vs cenew )

  (vl-load-com)

  (defun *error* ( m )
    (if ct
      (setvar 'ctab ct)
    )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (setq ct (getvar 'ctab))
  (foreach lay (layoutlist)
    (setvar 'ctab lay)
    (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 lay))))
    (repeat (setq i (sslength ss))
      (setq vp (ssname ss (setq i (1- i))))
      (vla-display (vlax-ename->vla-object vp) :vlax-true)
      (vla-put-mspace *adoc* :vlax-true)
      (vl-catch-all-apply 'vla-put-activepviewport (list *adoc* (vlax-ename->vla-object vp)))
      (setq ce (getvar 'viewctr))
      (setq vs (getvar 'viewsize))
      (setq cenew (mapcar '+ ce '(0.0 6558.8231 0.0)))
      (vl-cmdf "_.zoom" "_c" "_non" cenew vs)
      (vla-put-mspace *adoc* :vlax-false)
    )
  )
  (*error* nil)
)

HTH., M.R.

Cheers...


 

I was testing your routines...

...Work as you said. pretty cool, I'm new in coding and in AutoCAD, I was thinking this is not possible because I did not found something like this in 1000 pages.

I just have two requests more:

1) Can you add an option your lisp-routines to work only in selected layout-tabs? 

...like this:

 

image.png

 

2) Can you add a variable to input a different coordinate value each time I need to?

 

image.png

 

 

 

 

 

0 Likes
Message 8 of 14

marko_ribar
Advisor
Advisor

I think this will be good... BTW. You have to have A2012+...

 

(defun c:processviewportsinallsellayouts ( / *error* selectedlayoutlist *adoc* ct ss i vp ce vs cenew ch v p1 p2 loop )

  (vl-load-com)

  (defun *error* ( m )
    (if ct
      (setvar 'ctab ct)
    )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (defun selectedlayoutlist ( / e lst )

    (vl-load-com)

    (vlax-for lay (vla-get-layouts (if *adoc* *adoc* (vla-get-activedocument (vlax-get-acad-object))))
      (setq e (vlax-vla-object->ename lay))
      (if (= (getpropertyvalue e "TabSelected") 1)
        (setq lst (cons (getpropertyvalue e "LayoutName") lst))
      )
    )
    (reverse lst)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (initget "Pick Specify")
  (setq ch (getkword "\nChoose option of translation vector input [Pick/Specify] <Specify coordinates> : "))
  (if (null ch)
    (setq ch "Specify")
  )
  (setq loop t)
  (if (= ch "Specify")
    (while loop
      (initget 1)
      (setq v (getpoint "\nSpecify coordinates of vector translation : "))
      (if (null (acet-sys-lmouse-down)) (setq loop nil))
    )
    (progn
      (initget 1)
      (setq p1 (getpoint "\nPick or specify start point of translation vector : "))
      (initget 1)
      (setq p2 (getpoint p1 "\nPick or specify end point of translation vector : "))
      (setq v (mapcar '- p2 p1))
    )
  )
  (setq ct (getvar 'ctab))
  (if (vl-remove "Model" (selectedlayoutlist))
    (foreach lay (vl-remove "Model" (selectedlayoutlist))
      (setvar 'ctab lay)
      (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 lay))))
      (repeat (setq i (sslength ss))
        (setq vp (ssname ss (setq i (1- i))))
        (vla-display (vlax-ename->vla-object vp) :vlax-true)
        (vla-put-mspace *adoc* :vlax-true)
        (vl-catch-all-apply 'vla-put-activepviewport (list *adoc* (vlax-ename->vla-object vp)))
        (setq ce (getvar 'viewctr))
        (setq vs (getvar 'viewsize))
        (setq cenew (mapcar '+ ce v))
        (vl-cmdf "_.zoom" "_c" "_non" cenew vs)
        (vla-put-mspace *adoc* :vlax-false)
      )
    )
  )
  (*error* nil)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 9 of 14

jtm2020hyo
Collaborator
Collaborator

@marko_ribar wrote:

I think this will be good... BTW. You have to have A2012+...

 

(defun c:processviewportsinallsellayouts ( / *error* selectedlayoutlist *adoc* ct ss i vp ce vs cenew ch v p1 p2 loop )

  (vl-load-com)

  (defun *error* ( m )
    (if ct
      (setvar 'ctab ct)
    )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (defun selectedlayoutlist ( / e lst )

    (vl-load-com)

    (vlax-for lay (vla-get-layouts (if *adoc* *adoc* (vla-get-activedocument (vlax-get-acad-object))))
      (setq e (vlax-vla-object->ename lay))
      (if (= (getpropertyvalue e "TabSelected") 1)
        (setq lst (cons (getpropertyvalue e "LayoutName") lst))
      )
    )
    (reverse lst)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (initget "Pick Specify")
  (setq ch (getkword "\nChoose option of translation vector input [Pick/Specify] <Specify coordinates> : "))
  (if (null ch)
    (setq ch "Specify")
  )
  (setq loop t)
  (if (= ch "Specify")
    (while loop
      (initget 1)
      (setq v (getpoint "\nSpecify coordinates of vector translation : "))
      (if (null (acet-sys-lmouse-down)) (setq loop nil))
    )
    (progn
      (initget 1)
      (setq p1 (getpoint "\nPick or specify start point of translation vector : "))
      (initget 1)
      (setq p2 (getpoint p1 "\nPick or specify end point of translation vector : "))
      (setq v (mapcar '- p2 p1))
    )
  )
  (setq ct (getvar 'ctab))
  (if (vl-remove "Model" (selectedlayoutlist))
    (foreach lay (vl-remove "Model" (selectedlayoutlist))
      (setvar 'ctab lay)
      (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 lay))))
      (repeat (setq i (sslength ss))
        (setq vp (ssname ss (setq i (1- i))))
        (vla-display (vlax-ename->vla-object vp) :vlax-true)
        (vla-put-mspace *adoc* :vlax-true)
        (vl-catch-all-apply 'vla-put-activepviewport (list *adoc* (vlax-ename->vla-object vp)))
        (setq ce (getvar 'viewctr))
        (setq vs (getvar 'viewsize))
        (setq cenew (mapcar '+ ce v))
        (vl-cmdf "_.zoom" "_c" "_non" cenew vs)
        (vla-put-mspace *adoc* :vlax-false)
      )
    )
  )
  (*error* nil)
)



Your code works perfectly, just I need a minor fix.

 

 

 

image.png

 

when I move to any direction, your lisp move the viewport target distance X2

 

example: 

 

when I want to move layout "12(2)" viewport to see "drawing 21", 100 units to the right, I need input 50 units

 

I need to input 100 units to move 100 units.

 

image.png

 

Anyway, I will keep testing your code a bit more before mark as solution.

 

PD: It is possible to pan viewport without join layouts individually?

0 Likes
Message 10 of 14

marko_ribar
Advisor
Advisor
Accepted solution

Yes, you are right... That thing is because selection set of viewports is grabbed with main layout viewport which shouldn't be in selection set... So routine processed all viewports and finally as last one it processed layout viewport making pan once again for all viewports for the same distance... Here is revision of the code :

 

(defun c:processviewportsinallsellayouts ( / *error* selectedlayoutlist *adoc* ct ss i vp ce vs cenew ch v p1 p2 loop )

  (vl-load-com)

  (defun *error* ( m )
    (if ct
      (setvar 'ctab ct)
    )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (defun selectedlayoutlist ( / e lst )

    (vl-load-com)

    (vlax-for lay (vla-get-layouts (if *adoc* *adoc* (vla-get-activedocument (vlax-get-acad-object))))
      (setq e (vlax-vla-object->ename lay))
      (if (= (getpropertyvalue e "TabSelected") 1)
        (setq lst (cons (getpropertyvalue e "LayoutName") lst))
      )
    )
    (reverse lst)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (initget "Pick Specify")
  (setq ch (getkword "\nChoose option of translation vector input [Pick/Specify] <Specify coordinates> : "))
  (if (null ch)
    (setq ch "Specify")
  )
  (setq loop t)
  (if (= ch "Specify")
    (while loop
      (initget 1)
      (setq v (getpoint "\nSpecify coordinates of vector translation : "))
      (if (null (acet-sys-lmouse-down)) (setq loop nil))
    )
    (progn
      (initget 1)
      (setq p1 (getpoint "\nPick or specify start point of translation vector : "))
      (initget 1)
      (setq p2 (getpoint p1 "\nPick or specify end point of translation vector : "))
      (setq v (mapcar '- p2 p1))
    )
  )
  (setq ct (getvar 'ctab))
  (if (vl-remove "Model" (selectedlayoutlist))
    (foreach lay (vl-remove "Model" (selectedlayoutlist))
      (setvar 'ctab lay)
      (setq ss (ssget "_X" (list '(0 . "VIEWPORT") '(-4 . "<not") '(69 . 1) '(-4 . "not>") (cons 410 lay))))
      (repeat (setq i (sslength ss))
        (setq vp (ssname ss (setq i (1- i))))
        (vla-display (vlax-ename->vla-object vp) :vlax-true)
        (vla-put-mspace *adoc* :vlax-true)
        (vl-catch-all-apply 'vla-put-activepviewport (list *adoc* (vlax-ename->vla-object vp)))
        (setq ce (getvar 'viewctr))
        (setq vs (getvar 'viewsize))
        (setq cenew (mapcar '+ ce v))
        (vl-cmdf "_.zoom" "_c" "_non" cenew vs)
        (vla-put-mspace *adoc* :vlax-false)
      )
    )
  )
  (*error* nil)
)

This issue will occur and in my code for processing all layouts, so be sure to copy line (setq ss (ssget "_X" (list '(0 . "VIEWPORT") '(-4 . "<not") '(69 . 1) '(-4 . "not>") (cons 410 lay)))) and in that code... Not quite sure, but in DXF reference it is stated that code 69 is viewport ID, so I think ID=1 is main layout viewport which should be filtered out...

 

For your question : single viewport pan - yes you have code which should work fine, just copy+paste what I wrote in this code for user inputs for vector of translation...

 

Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 11 of 14

alx86
Enthusiast
Enthusiast
Thanks  I was also searching for something like this! But is there a way to change the pan from Y axis to X? I need the same, but I need to move my viewports horizontally instead of vertically.

Thanks a lot

Message 12 of 14

jtm2020hyo
Collaborator
Collaborator

this lisp works for x and y

0 Likes
Message 13 of 14

ruqaiyakothariMWJH9
Observer
Observer

Worked a charm. Thannk you soooo much!!

Message 14 of 14

3dwannab
Advocate
Advocate
Accepted solution

Thanks mark, 

 

I modified it to do a selection of viewports to unlock and lock any that were afterwards and to enter the offset of the pan in both the X and Y direction.

 

;; Pans a selection of viewports in the X and Y direction.

;; This is a modification of the program here by marko_ribar: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pan-all-viewports-in-selected-layouts/m-p/8577783#M380669

;; 3dwannab modifications on 2022.08.04 are:
;; You can select locked viewports and this will temporarily unlock them, do its business and then locks them again.
;; Message error if in modelspace.
;; Allows the user to enter X and Y offsets.

(defun c:VP_Pan_Selected (/ *error* *adoc* ce cenew ct i lock offX offY pt ss vp vs)

  (vl-load-com)

  (if (= (getvar 'tilemode) 1)
    (progn
      (acet-ui-message "You must be in paperspace for this to work!" "Computer says no.." 48)
      (exit)
    )
  )

  (defun *error* (m)
    (if ct
      (setvar 'ctab ct)
    )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))

  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (setq ct (getvar 'ctab))

  (vla-put-mspace *adoc* :vlax-false)

  (if

    (and
      (setq ss (ssget (list '(0 . "VIEWPORT"))))
      (setq pt (getpoint "\nEnter X, Y Offset (Moves objects in this direction):\n"))
    )

    (repeat (setq i (sslength ss))

      (setq vp (ssname ss (setq i (1- i))))
      (vla-display (vlax-ename->vla-object vp) :vlax-true)
      (vla-put-mspace *adoc* :vlax-true)
      (vl-catch-all-apply 'vla-put-activepviewport (list *adoc* (vlax-ename->vla-object vp)))

      (setq lock (vla-get-displaylocked (vlax-ename->vla-object vp)))
      (vla-put-displaylocked (vlax-ename->vla-object vp) :vlax-false)

      (setq ce (getvar 'viewctr))
      (setq vs (getvar 'viewsize))

      (setq offX (- 0.0 (car pt))) ;; Opposite the X value so it's easier to visualise the movement of the objects in the viewport.
      (setq offY (- 0.0 (nth 1 pt))) ;; Opposite the Y value so it's easier to visualise the movement of the objects in the viewport.

      (setq cenew (mapcar '+ ce (list offX offY 0.0)))

      (vl-cmdf "_.zoom" "_c" "_non" cenew vs)
      (vla-put-mspace *adoc* :vlax-false)
      (vla-put-displaylocked (vlax-ename->vla-object vp) lock)
    )
  )

  (*error* nil)
)

;; (c:VP_Pan_Selected) ;; Unblock for quick testing