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

0 Members and 1 Guest are viewing this topic.

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.