TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Sdoman on July 11, 2006, 04:36:30 PM

Title: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 11, 2006, 04:36:30 PM

I am trying to construct a list containing a sublist for each paperspace layout in the drawing.  The Car of a sublist will be the layout name (string). The Cdr of a sublist will be another list containing all paperspace vport objects references for that particular layout.

Here is an example of a list I am trying to construct:

 
Code: [Select]
(("Layout1"
     (#<VLA-OBJECT IAcadPViewport 064a9324>
      #<VLA-OBJECT IAcadPViewport 064a8c54>
     )
   )
    ("Layout2"
      (#<VLA-OBJECT IAcadPViewport 064a88a4>
       #<VLA-OBJECT IAcadPViewport 064a84f4>
       #<VLA-OBJECT IAcadPViewport 064adc54>
      )
    )
    ...
  )

My problem is I don't want to include the paperspace viewport.  I thought I could eliminate the paperspace viewport by using ssget with a dxf filter.  However I am getting mixed results, sometimes it works, othertimes it doesn't.  So I am not sure if this is a correct way to accomplish this task.

Here's the code I have so far.  The first function is what I am working on.  The other two are supporting functions:

Code: [Select]
(defun sd:VpList (/ ss rslt)
  ;;
  ;; Returns a list of layout names and vports objects
  ;; Requires subfunction LayoutList< and ss->objlst
  ;;
  (foreach layout (sd:LayoutList<)
    (if (setq ss (ssget "x"
                        (list '(0 . "VIEWPORT")
                              (cons 410 layout)
                              '(-4 . ">") 
                              '(68 . 0)  ;_ viewport status
                        )
                 )
        )
      (setq rslt (cons (list layout (sd:ss->objlst ss)) rslt))
    )
  )
  (reverse rslt)
)

Code: [Select]
(defun sd:LayoutList< (/ layout name index)
  ;; sdoman
  ;; Returns list of layout names sorted by taborder
  ;; Excludes the "Model" layoutname
  ;;
  (vlax-for layout (vla-get-layouts
                  (vla-get-activedocument (vlax-get-acad-object))
                )
    (setq name  (cons (vla-get-name layout) name)
          index (cons (vla-get-taborder layout) index)
    )
  )
  (cdr (mapcar '(lambda (x) (nth x name)) (vl-sort-i index '<)))
)

Code: [Select]
(defun sd:ss->objlst (ss / n lst)
  ;; Returns a list of vla-objects given a selection set
  (cond ((= (type ss) 'PICKSET)
         (setq n 0)
         (repeat (sslength ss)
           (setq lst (cons (vlax-ename->vla-object (ssname ss n)) lst)
                 n   (1+ n)
           )
         )
         (reverse lst)
        )
  )
)

Thanks,
Steve
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: T.Willey on July 11, 2006, 05:10:24 PM
How about if you check for dxf code 69.  I think that if it's 1 then it is the paper space viewport.
Code: [Select]
(defun sd:VpList (/ ss rslt)
  ;;
  ;; Returns a list of layout names and vports objects
  ;; Requires subfunction LayoutList< and ss->objlst
  ;;
  (foreach layout (sd:LayoutList<)
    (if (setq ss (ssget "x"
                        (list '(0 . "VIEWPORT")
                              (cons 410 layout)
                              '(-4 . ">") 
                              '(69 . 0)  ;_ viewport number
                        )
                 )
        )
      (setq rslt (cons (list layout (sd:ss->objlst ss)) rslt))
    )
  )
  (reverse rslt)
)
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 11, 2006, 05:24:50 PM
How about if you check for dxf code 69.  I think that if it's 1 then it is the paper space viewport.
Code: [Select]
(defun sd:VpList (/ ss rslt)
  ;;
  ;; Returns a list of layout names and vports objects
  ;; Requires subfunction LayoutList< and ss->objlst
  ;;
  (foreach layout (sd:LayoutList<)
    (if (setq ss (ssget "x"
                        (list '(0 . "VIEWPORT")
                              (cons 410 layout)
                              '(-4 . ">") 
                              '(69 . 0)  ;_ viewport number
                        )
                 )
        )
      (setq rslt (cons (list layout (sd:ss->objlst ss)) rslt))
    )
  )
  (reverse rslt)
)

Tim

Thanks but that doesn't to work for me.  Wait let me check something...

Ok if I change the filter to: '(-4 . ">") '(69 . 1), it *seems* to work.  Going to do some testing...


fixd typo: dxf 69 -> 1

Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: T.Willey on July 11, 2006, 05:59:38 PM
You are right Steve.  I meant to put '(69 . 1).  It worked on a quick little test I did here.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: MP on July 11, 2006, 06:01:56 PM
Edit: Modified to test for valid selection set, lest it bomb.

Not sure I follow but this quick & dirty --

Code: [Select]
(defun foo ( / ss result key exist )
    (if
        (setq ss
            (ssget "x"
               '(   
                    (0 . "VIEWPORT")
                    (-4 . "!=") 
                    (69 . 1)
                    (-4 . ">")
                    (68 . 0)
                )
            )
        )
        (vl-sort
            (foreach ename (mapcar 'cadr (ssnamex ss))
                (setq result
                    (if
                        (setq exist
                            (assoc
                                (setq key (cdr (assoc 410 (entget ename))))
                                result
                            )
                        )
                        (subst
                            (list key
                                (cons
                                    (vlax-ename->vla-object ename)
                                    (cadr exist)
                                )
                            )
                            exist
                            result
                        )
                        (cons
                            (list key (list (vlax-ename->vla-object ename)))
                            result
                        )
                    )
                )   
            )
           '(lambda (a b) (< (car a) (car b)))
        )
    )   
)

Spews this --

Code: [Select]
(   
    (   "Layout1"
        (   #<VLA-OBJECT IAcadPViewport 02c1e9f4>
            #<VLA-OBJECT IAcadPViewport 02c36734>
        )
    )
    (   "Layout2"
        (
            #<VLA-OBJECT IAcadPViewport 02c1e8c4>
            #<VLA-OBJECT IAcadPViewport 02c2b904>
            #<VLA-OBJECT IAcadPViewport 02c365b4>
        )
    )
)

Use [abuse|discard|ignore] as you see fit.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: T.Willey on July 11, 2006, 06:16:33 PM
Nice code Michael.  I see more and more post with people using "ssnamex".  Guess it's time to learn a new trick.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: MP on July 11, 2006, 06:32:48 PM
Thanks Tim, please see the edit.

PS: A nod to our friend Evgeniy who illuminated the use of ssnamex.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 11, 2006, 06:37:22 PM
Nice one MP.  Your code works well! And the ssget filter you used is interesting.

And what Tim said.  The ssnamex function is something I rarely have used.  That's so cool how you used it to get a list of enames.



Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: MP on July 11, 2006, 11:14:52 PM
Thanks Steve, just havin' some good ol' lispin' fun. Glad if it helps even if just a little.

:)
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 11, 2006, 11:39:56 PM
MP,

It does help and thank you very much for posting.  I must admit to being a bit overwhelmed at first while trying to understand your algorithm.  But now that I've had a chance to study it, I find the code within the foreach loop really interesting.

Could you please comment on your ssget filter?  The help files totally confused me on which dxf code to use.  I think what your are filtering is: select all viewports which are on and not "Thee Paper Space" viewport. Right?


Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: MP on July 11, 2006, 11:52:24 PM
Hi Steve. As I understand it ssget filtering, without -4 groups to specify otherwise, employs implied and all the way.

So the filter as written says --

Select all entities that are viewports AND have an ID that is not equal to 1 (paperspace) AND have a status that is greater than 0 (on and active).

That is what I thought you wanted; hope I didn't veer too far of the desired track.

:)

Happiness thru drugs; oh bliss.

PS: My pleasure Steve.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 12, 2006, 12:15:18 AM
MP,

Coolness.  That is exactly what I want. Thanks.

Have a nice bliss : )
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: MP on July 12, 2006, 06:54:46 AM
Thanks Steve, that makes me happer than a dung beetle at an elephant parade, or something like that.

 :lol:
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 12, 2006, 10:22:40 AM
Shoot!  Still having problems:

I came to work this morning, fired up AutoCAD, opened my test drawing that contains several paperspace layouts, Then I loaded and the 'foo function.  It returned a list containing the data for the current layout, but not the others.  I suspect the ssget filter is the problem.  Perhaps when a drawing is first opened, the viewports are not activated until the layout the viewport is located on is made active.

Any ideas?  Attached is drawing file I am using for testing (saved as a2k file format).
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: MP on July 12, 2006, 10:27:37 AM
I can't D/L from here (mumble ...). Try this --

Code: [Select]
(ssget "x"
   '(   
        (0 . "VIEWPORT")
        (-4 . "!=") 
        (69 . 1)
        (-4 . "!=")
        (68 . 0)
    )
)

It limits the selection to viewports that are not off, which means viewports that are on but not active (or visible, like off screen, maxactvp exceeded yada) can be selected. HTH.

/Shrug.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 12, 2006, 10:39:33 AM
Thanks MP, but no worky - i think - still testing.  Returns a viewport object on all layouts, but the last layout in the drawing has no viewport.  Going to do some research...
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 12, 2006, 10:55:06 AM
I can't D/L from here (mumble ...). Try this --

Code: [Select]
(ssget "x"
   '(   
        (0 . "VIEWPORT")
        (-4 . "!=") 
        (69 . 1)
        (-4 . "!=")
        (68 . 0)
    )
)

Weird - looking at the ssget filter I don't see how the selection set could contain the paperspace viewport -> dxf 69=1.  But it does that when I run the 'foo function (or the code I posted with same filter) on a the freshly opened test drawing.  If I initialize each layout by manually clicking on each tab, the code works perfect.

I got to do some drawing so will have to come back to this later... Thanks.

Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: LE on July 12, 2006, 11:29:58 AM
Doing a salad lisp mix ( and every day getting worst on lisping...  :-( )

Code: [Select]
(setq layouts (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))
(mapcar '(lambda (layout)
   (if (setq ss (ssget "x"
       (list '(0 . "VIEWPORT")
     '(-4 . "!=")
     '(69 . 1)
     '(-4 . "!=")
     '(68 . 0)
     (cons 410 (vla-get-name (vla-item layouts layout))))))
     (list layout (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))))
(layoutlist)))
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 12, 2006, 01:07:10 PM
Doing a salad lisp mix ( and every day getting worst on lisping...  :-( )

Code: [Select]
(setq layouts (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))
(mapcar '(lambda (layout)
   (if (setq ss (ssget "x"
       (list '(0 . "VIEWPORT")
     '(-4 . "!=")
     '(69 . 1)
     '(-4 . "!=")
     '(68 . 0)
     (cons 410 (vla-get-name (vla-item layouts layout))))))
     (list layout (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))))
(layoutlist)))

Looks good Luis.  But same problem about non-initialized layout tabs.  In other words if you run the code on the test drawing immediatley after opening the drawing, before clicking on any tabs, it returns all viewport including the paperspace viewport and including off viewports.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: LE on July 12, 2006, 01:26:57 PM
I'll see later today, if I can write something in arx (not sure).... right now I have to clean the toilets.... (kind of a real work to do) :-(

Also I need to exactly understand what is what you want.... with two sugar spoons or one and how many of coffee... yikes I am all lost now.....
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 12, 2006, 01:28:16 PM
Sorry, I hit the post button to soon...

So there is something funny going on with regards to the ssget filter and uninitialized layout tabs.  If I click on all the tabs then run your code, it's perfect.  As a work around, I could have the routine iterate through layouts to initialize them, but I was hoping to avoid that layout thrashing.

As I was typing you posted reply.  I need to do some drawing so have to work too.  Thanks.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: T.Willey on July 12, 2006, 01:41:45 PM
I don't see a way with just coding to test to see if the viewports are active once the layout is activated.  Hope I'm wrong here, it would really stink if you had to make each layout current once just to run the code.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 12, 2006, 03:02:40 PM
Ok thanks for the help Tim, Luis, & Michael.  Since we cannot find a method at this time for getting active vports objects without activating the layouts which they reside, I'll iterate through the layoutlist making each layout active and ssgetting the vports on the current layout, and build the list etc..

It's been an interesting discussion and I learned a few tricks.  Thanks for participating and hope you enjoyed the show too.  Meanwhile if anyone finds a solution, I'd appreciate reading about it.

Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: CAB on July 12, 2006, 05:25:27 PM
Steve,
I'm confused as usual ;)

You want a list of all viewports in paper space except the paper space itself.
Or only "Active Viewports".
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 12, 2006, 05:41:35 PM
Steve,
I'm confused as usual ;)

You want a list of all viewports in paper space except the paper space itself.
Or only "Active Viewports".

Hi CAB.  I'm confused too.  Here's the deal. 

I am trying to make a list of paperspace viewports objects.  The list must contain all  viewports in the drawing that are turned on, and are not "The Paper Space Viewport" - which as Tim pointed out has an id of 1.

The problem is if you run any of the fine examples posted so far, they don't return the correct data unless you make each layout active at some point prior to running the code.  If you activate each layout, one at a time, then run the code they work perfect.

Clear as mud?  I uploaded a test drawing on an earlier post if you want to try, or create your own test drawing.

Thanks for your inquiry.



Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: CAB on July 12, 2006, 06:24:42 PM
Consider this rough draft
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-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
)
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: LE on July 12, 2006, 06:37:00 PM
Appears to be Master Alan;

I think I am out of the lisp league.....  :cry:
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 12, 2006, 06:51:26 PM
Cab, you are my hero.  I did a very quick test and it worked super!  I need to leave for a meeting, will test further tonight at home.  Thanks so much.

LE, you are my hero too.
 
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: T.Willey on July 12, 2006, 07:04:13 PM
Hate to be a party pooper, but I don't think Alan's work correctly.  I dl'ed Steve's drawing.  Turned off one of the viewports in tab 2, switched to tab 1, saved the drawing, exited, and reopened it.  Ran Alan's code, and it still says that there are three vp's in tab 2 when there should only be two.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: CAB on July 12, 2006, 07:24:29 PM
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.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: T.Willey on July 12, 2006, 07:26:40 PM
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.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: T.Willey on July 12, 2006, 07:49:02 PM
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.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: MP on July 12, 2006, 08:01:29 PM
Lots of effort in this thread, kudos to all of you!

:)
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: CAB on July 12, 2006, 08:28:07 PM
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>
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Sdoman on July 13, 2006, 07:57:08 AM
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
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Kerry on July 13, 2006, 08:07:11 AM
Well done guys, I really enjoy the spirit exhibited in of this place, and the skills !
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: T.Willey on July 13, 2006, 11:01:43 AM
I had fun.  I like ones that are challenging.  Whats next?

Good work Alan.
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: CAB on July 13, 2006, 11:41:03 AM
Thanks you Sir's, great effor all, twas fun indeed. :-)
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Patrick_35 on June 30, 2008, 11:07:02 AM
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>))
)

@+
Title: Re: Eliminate the Paper Space Viewport from a list of all viewports on a layout
Post by: Paulli_apa on January 12, 2024, 04:48:41 PM
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.