delete the same viewports from all layouts

delete the same viewports from all layouts

E.S.7.9
Advocate Advocate
1,672 Views
7 Replies
Message 1 of 8

delete the same viewports from all layouts

E.S.7.9
Advocate
Advocate

hi

 

i have too many layouts in my drawing and they have some viewports exactly the same location in alll layouts , i want to delete this viewports from all layouts but i dont want to do it one by one ...

 

can anybody share with me the similar lisp code ? or explain how to easily delete them

 

thank you ...

0 Likes
Accepted solutions (1)
1,673 Views
7 Replies
Replies (7)
Message 2 of 8

hmsilva
Mentor
Mentor
Accepted solution

@E.S.7.9 wrote:

i have too many layouts in my drawing and they have some viewports exactly the same location in alll layouts , i want to delete this viewports from all layouts but i dont want to do it one by one ...

...

can anybody share with me the similar lisp code ? or explain how to easily delete them

...


Hi E.S.7.9,

try

(vl-load-com)
(defun c:demo (/ *error* I LL LLPT ORG_LLPT ORG_URPT ORG_VP S SS UR URPT VP)

    (defun *error* (msg)
        (if adoc
            (vla-Endundomark adoc)
        )
        (cond ((not msg))
              ((member msg '("Function cancelled" "quit / exit abort")))
              ((princ (strcat "\n** Error: " msg " ** ")))
        )
        (princ)
    )
    
    (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
    (vla-Startundomark adoc)
    (if (and (princ "\nSelect a Viewport to erase ALL Viewports in the same place, in ALL layouts: ")
             (setq s (ssget "_+.:E:S" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1))))
             (setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1))))
        )
        (progn
            (setq org_vp (vlax-ename->vla-object (ssname s 0)))
            (vlax-invoke-method org_vp 'GetBoundingBox 'll 'ur)
            (setq org_llpt (vlax-safearray->list ll)
                  org_urpt (vlax-safearray->list ur)
            )
            (repeat (setq i (sslength ss))
                (setq vp (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
                (vlax-invoke-method vp 'GetBoundingBox 'll 'ur)
                (setq llpt (vlax-safearray->list ll)
                      urpt (vlax-safearray->list ur)
                )
                (if (and (equal org_llpt llpt 1e-6)
                         (equal org_urpt urpt 1e-6)
                         (vlax-write-enabled-p vp)
                    )
                    (vla-delete vp)
                )
            )
        )
    )
    (*error* nil)
    (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 3 of 8

Anonymous
Not applicable

If the viewport is in the exact same location, get the coordinates of the center of the viewport and change (list 0.0 0.0) to your coordinates -

(defun C:DelVP ()
  (foreach Item (layoutlist)
    (setvar "CTAB" Item)
    (if (setq SS (ssget "X" (list (cons 0 "VIEWPORT") (cons 410 Item) (cons 10 (list 2.5 2.5)))))
      (command "ERASE" SS "")
    )
  )
  (princ)
)

0 Likes
Message 4 of 8

E.S.7.9
Advocate
Advocate

it s working perfect , thank you

0 Likes
Message 5 of 8

hmsilva
Mentor
Mentor

@E.S.7.9 wrote:

it s working perfect , thank you


You're welcome, E.S.7.9
Glad I could help

Henrique

EESignature

0 Likes
Message 6 of 8

ATm_KLT
Explorer
Explorer

Hello!

 

I use this code very often and I love it, but sometimes i need to keep the viewport on the current layout and only erase on the others.

 

I have tried to modify the code but with no luck, can you help me?

 

Thanks.

Anders Tengbom, Sweden

 

 

 

 

0 Likes
Message 7 of 8

dlanorh
Advisor
Advisor

Try this. It will delete viewports not on the active layout tab, i.e. the one you select the viewport on.

 

 

(vl-load-com)
(defun c:demo (/ *error* I LL LLPT ORG_LLPT ORG_URPT ORG_VP S SS UR URPT VP)

  (defun *error* (msg)
      (if adoc (vla-Endundomark adoc))
      (cond ((not msg))
            ((member msg '("Function cancelled" "quit / exit abort")))
            ((princ (strcat "\n** Error: " msg " ** ")))
      )
      (princ)
  )
  
  (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
  (vla-Startundomark adoc)
  (if (and (princ "\nSelect a Viewport to erase ALL Viewports in the same place, in ALL layouts: ")
           (setq s (ssget "_+.:E:S" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1))))
           (setq ss (ssget "_X" (list '(0 . "VIEWPORT") '(-4 . "!=") '(69 . 1) '(-4 . "<NOT") (cons 410 (getvar 'ctab)) '(-4 . "NOT>"))))
      )
      (progn
          (setq org_vp (vlax-ename->vla-object (ssname s 0)))
          (vlax-invoke-method org_vp 'GetBoundingBox 'll 'ur)
          (setq org_llpt (vlax-safearray->list ll)
                org_urpt (vlax-safearray->list ur)
          )
          (repeat (setq i (sslength ss))
              (setq vp (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
              
              (vlax-invoke-method vp 'GetBoundingBox 'll 'ur)
              (setq llpt (vlax-safearray->list ll)
                    urpt (vlax-safearray->list ur)
              )
              (if (and (equal org_llpt llpt 1e-6)
                       (equal org_urpt urpt 1e-6)
                       (vlax-write-enabled-p vp)
                  )
                  (vla-delete vp)
              )
          )
      )
  )
  (*error* nil)
  (princ)
)

 

 

 

I am not one of the robots you're looking for

Message 8 of 8

ATm_KLT
Explorer
Explorer

Thank you , works perfect

I was almost on the right track with my own editing….  but now i get it😀

 

/ Anders Tengbom

0 Likes