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

0 Members and 1 Guest are viewing this topic.

Sdoman

  • Guest

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

T.Willey

  • Needs a day job
  • Posts: 5251
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

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

Please think about donating if this post helped you.

Sdoman

  • Guest
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

« Last Edit: July 11, 2006, 05:28:49 PM by 'steved »

T.Willey

  • Needs a day job
  • Posts: 5251
You are right Steve.  I meant to put '(69 . 1).  It worked on a quick little test I did here.
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.
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.
« Last Edit: July 11, 2006, 06:20:32 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Nice code Michael.  I see more and more post with people using "ssnamex".  Guess it's time to learn a new trick.
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.
Thanks Tim, please see the edit.

PS: A nod to our friend Evgeniy who illuminated the use of ssnamex.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Sdoman

  • Guest
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.




MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Thanks Steve, just havin' some good ol' lispin' fun. Glad if it helps even if just a little.

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

Sdoman

  • Guest
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?



MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Sdoman

  • Guest
MP,

Coolness.  That is exactly what I want. Thanks.

Have a nice bliss : )

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Thanks Steve, that makes me happer than a dung beetle at an elephant parade, or something like that.

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

Sdoman

  • Guest
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).

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Sdoman

  • Guest
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...

Sdoman

  • Guest
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.


LE

  • Guest
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)))

Sdoman

  • Guest
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.

LE

  • Guest
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.....

Sdoman

  • Guest
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.

T.Willey

  • Needs a day job
  • Posts: 5251
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.
Tim

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

Please think about donating if this post helped you.

Sdoman

  • Guest
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.


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
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".
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
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.




CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
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
)
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.

LE

  • Guest
Appears to be Master Alan;

I think I am out of the lisp league.....  :cry:

Sdoman

  • Guest
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.
 

T.Willey

  • Needs a day job
  • Posts: 5251
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.
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
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.
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.

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 »