Author Topic: Eliminate the Paper Space Viewport from a list of all viewports on a layout  (Read 17208 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Don't get too excited I still haven't conquered the ON/Off thing, just separated out the Paper Space.
So if the vp is OFF it is included in the list, But I'm still looking.
Here I was thinking you had it all solved, and I was like "How??!!?" with little kid eyes, shaking with anticipation.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Here is one that works the way it should.  Most of the code is Alan's, I just added one line.
Code: [Select]
(defun foo (/ ss result vpl tab exc tmp)
  (defun get_exc (vpe / a b c)
    (and
    (setq a (cdr (assoc 330 (entget vpe))))
    (setq b (cdr (assoc 340 (entget a))))
    (setq c (cdr (assoc 331 (entget b))))
    )
    c
  )

  (if (setq ss (ssget "x" '((0 . "VIEWPORT"))))
    (progn
      (setq vpl (mapcar 'cadr (ssnamex ss)))
      (setq vpl (mapcar '(lambda (x) (cons x (cdr (assoc 410 (entget x))))) vpl))
      (setq vpl (vl-remove-if '(lambda (x) (equal 131072 (logand 131072 (cdr (assoc 90 (entget (car x))))))) vpl)) ;; TMW
      (setq vpl (vl-sort vpl '(lambda (e1 e2) (< (cdr e1) (cdr e2)))))
      (foreach vp vpl
        (cond
          ((null tab)
           (setq tab (cdr vp)
                 exc (get_exc (car vp))
           )
          )
          ((= tab (cdr vp))
           (if (not (= exc (car vp)))
             (setq tmp (cons (car vp) tmp))
           )
          )
          (t
           (setq exc    (get_exc (car vp))
                 result (if result
                          (cons (list tab tmp) result)
                          (list (list tab tmp))
                        )
                 tab    (cdr vp)
                 tmp    nil
           )
          )
        )
      )
      (if tmp
        (setq result (if result
                       (cons (list tab tmp) result)
                       (list (list tab tmp))
                     )
        )
      )
    )
  )
  result
)
Here is the line of code I used to test it.
Code: [Select]
(mapcar '(lambda (x) (cons (car x) (length (cadr x)))) (foo))
Here is the help area that showe me what to try.
Quote
90
 Viewport status bit-coded flags:

1 (0x1) = Enables perspective mode

2 (0x2) = Enables front clipping

4 (0x4) = Enables back clipping

8 (0x8) = Enables UCS follow

16 (0x10) = Enables front clip not at eye

32 (0x20) = Enables UCS icon visibility

64 (0x40) = Enables UCS icon at origin

128 (0x80) = Enables fast zoom

256 (0x100) = Enables snap mode

512 (0x200) = Enables grid mode

1024 (0x400) = Enables isometric snap style

2048 (0x800) = Enables hide plot mode

4096 (0x1000) = kIsoPairTop. If set and kIsoPairRight is not set, then isopair top is enabled. If both kIsoPairTop and kIsoPairRight are set, then isopair left is enabled

8192 (0x2000) = kIsoPairRight. If set and kIsoPairTop is not set, then isopair right is enabled

16384 (0x4000) = Enables viewport zoom locking

32768 (0x8000) = Currently always enabled

65536 (0x10000) = Enables non-rectangular clipping

131072 (0x20000) = Turns the viewport off
Okay, time to go home now.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Lots of effort in this thread, kudos to all of you!

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
That was the last part of the puzzle.
Here is my version with flag.
 Only get vps that are ON if flag is true
(setq Vpon (foo t))


Code: [Select]
(defun foo (on? / ss result vpl tab exc tmp)
  ;;  Only get vps that are ON if flag is true
  (defun get_exc (vpe / a b c)
    (and
    (setq a (cdr (assoc 330 (entget vpe))))
    (setq b (cdr (assoc 340 (entget a))))
    (setq c (cdr (assoc 331 (entget b))))
    )
    c
  )

  (if (setq ss (ssget "x" '((0 . "VIEWPORT"))))
    (progn
      (setq vpl (mapcar 'cadr (ssnamex ss)))
      (setq vpl (mapcar '(lambda (x) (cons x (cdr (assoc 410 (entget x))))) vpl))
      (setq vpl (vl-sort vpl '(lambda (e1 e2) (< (cdr e1) (cdr e2)))))
      (foreach vp vpl
        (cond
          ((null tab)
           (setq tab (cdr vp)
                 exc (get_exc (car vp))
           )
          )
          ((= tab (cdr vp))
           (if (and (not (= exc (car vp)))
                    (or (not on?)
                        (zerop (logand 131072 (cdr (assoc 90 (entget (car vp))))))))
             (setq tmp (cons (car vp) tmp))
           )
          )
          (t
           (setq exc    (get_exc (car vp))
                 result (if result
                          (cons (list tab tmp) result)
                          (list (list tab tmp))
                        )
                 tab    (cdr vp)
                 tmp    nil
           )
          )
        )
      )
      (if tmp
        (setq result (if result
                       (cons (list tab tmp) result)
                       (list (list tab tmp))
                     )
        )
      )
    )
  )
  result
)

<edit: removed some floatsam>
« Last Edit: July 13, 2006, 08:13:27 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Sdoman

  • Guest
Bingo!  Excellent coding!  Thank you Cab and Tim for finding a solution.  Hi fives to everyone.  You guys really are awesome and exhibited some very highly skilled code. 

I had been stuck with that programming problem for a long time before I posted for help.  Really do appreciate the effort you guys made.  And I hope I can help you out some time.

Regards,
Steve Doman

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Well done guys, I really enjoy the spirit exhibited in of this place, and the skills !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

T.Willey

  • Needs a day job
  • Posts: 5251
I had fun.  I like ones that are challenging.  Whats next?

Good work Alan.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Thanks you Sir's, great effor all, twas fun indeed. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Patrick_35

  • Guest
Hi

An old post   :-)

I found a another solution

Code: [Select]
(defun view(/ doc ent fen sau vie)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vlax-for lay (vla-get-layouts doc)
    (setq vie nil
  sau nil
    )
    (vlax-for ent (vla-get-block lay)
      (if (and sau
      (eq (vla-get-objectname ent) "AcDbViewport")
  )
(setq vie (cons ent vie))
(setq sau T)
      )
    )
    (and vie
      (setq fen (cons (list (vla-get-name lay) vie) fen))
    )
  )
  fen
)

return a list with name of layout and a list of viewport
Example
(("Layout1" (#<VLA-OBJECT IAcadPViewport2 15148314>))
 ("Layout2" (#<VLA-OBJECT IAcadPViewport2 15148c64>))
 ("Layout3" (#<VLA-OBJECT IAcadPViewport2 151721a4> #<VLA-OBJECT IAcadPViewport2 15174c64>))
)

@+

Paulli_apa

  • Mosquito
  • Posts: 2
When a drawing first opens by default only a single layout is automatically activated. So all vports in that layout will have vport ids greater than 1 with that layout itself with a vport id of 1 which is why the following code works only when there's a single layout in the drawing:
(setq ss (ssget "_X" '((0 . "VIEWPORT")(-4 . "!=")(69 . 1))))
The problem with this approach is when a dwg first opens & there is more than a single layout all other layouts pspace vport ids are still left as 0 just like the layout vport id itself. So the above code will also selection those layout itself thinking that it's a pspace vport when it's not.
A way to activate all the other layouts pspace vports is to cycle through making each layout current which is a hassle when a drawing has lots of layout tabs.
« Last Edit: January 12, 2024, 06:04:24 PM by Paulli_apa »