Author Topic: Search for viewport ...  (Read 5019 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Search for viewport ...
« on: February 03, 2011, 02:21:17 PM »
Afternoon,

I am in a bit of a pinch here and need some help.

I have a bunch of drawings created from several different sources.  The problem I am having is that some of these drawings have a model drawn in model space and text in paper space, others have the model and text in paper space and there is no viewport or everything in Model space and there is no viewport.  In this case, sometimes there is the default "layout" tab and at other times there is a name to the layout tab even though there is no viewport attached to it.

I need to find a generic way of finding out what the drawing is like.
The only thing I can think of at the moment is searching for a viewport, so I'm using Mark's code:
Code: [Select]
(vlax-for Lyout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (if (eq :vlax-false (vla-get-modeltype Lyout))      ; if layout is other than Model
      (vlax-for Ent (vla-get-block Lyout)               ; for each entity in layout
        (if (= (vla-get-objectname Ent) "AcDbViewport") ; if there is a viewport
          (setq dwgVP 1)
          (setq dwgVP nil)
 < .. >

But my variable 'dwgVP' is coming up nil every time.

So can you kill two birds with one stone here?  I mean, I have done a search for "find viewport" and "search for viewport" but have come up empty.  So the question(s) here are; How do I go about searching for a viewport in the drawing?  I do have a few drawings where there are several tabs, and a drawing on each one with nothing in model space and no viewports, but a lot of tabs with different names so I can't search by a named tab.

And my second question would be; Do you have a suggestion to better determine if the drawing has a viewport and if so, how many, and on what tabs, and ...  what else can be added to this can of worms?

Thanks.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Search for viewport ...
« Reply #1 on: February 03, 2011, 02:32:28 PM »
?

Code: [Select]
(defun foo (/ ss)
  (foreach x (layoutlist) (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 x)))))
  (and ss (> (sslength ss) 1))
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Search for viewport ...
« Reply #2 on: February 03, 2011, 02:38:31 PM »
Code: [Select]
(defun foo (/ ss)
  (foreach x (layoutlist) (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 x)))))
  (and ss (> (sslength ss) 1))
)

But if the last layout doesn't have a Viewport, wouldn't that return nil? But maybe that's what the OP wants - i.e. to check either all or nothing...

I thought maybe:

Code: [Select]
(defun HasVP nil (vl-load-com)
  (vl-some
    (function
      (lambda ( layout )
        (ssget "_X" (list (cons 0 "VIEWPORT") (cons 410 layout)))
      )
    )
    (layoutlist)
  )
)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Search for viewport ...
« Reply #3 on: February 03, 2011, 02:43:17 PM »
Code: [Select]
(defun foo (/ ss)
  (foreach x (layoutlist) (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 x)))))
  (and ss (> (sslength ss) 1))
)

But if the last layout doesn't have a Viewport, wouldn't that return nil? But maybe that's what the OP wants - i.e. to check either all or nothing...

I thought maybe:

Code: [Select]
(defun HasVP nil (vl-load-com)
  (vl-some
    (function
      (lambda ( layout )
        (ssget "_X" (list (cons 0 "VIEWPORT") (cons 410 layout)))
      )
    )
    (layoutlist)
  )
)

Crap, forgot about that, but you also have to account for the viewport block that exists in every layout...

Code: [Select]
(defun foo (/)
  (vl-some
    (function (lambda (x) (and x (> (sslength x) 1))))
    (mapcar (function (lambda (x) (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 x))))) (layoutlist))
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Search for viewport ...
« Reply #4 on: February 03, 2011, 02:45:37 PM »
Actually, this would make more sense...

Code: [Select]
(defun foo (/)
  (vl-some
    (function
      (lambda (x / ss)
        (if (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 x))))
          (> (sslength ss) 1)
        )
      )
    )
    (layoutlist)
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Search for viewport ...
« Reply #5 on: February 03, 2011, 02:51:11 PM »
... but you also have to account for the viewport block that exists in every layout...

I don't think you do with an ssget call as I thought it will only select 'primary' objects, but will have to test to be certain.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Search for viewport ...
« Reply #6 on: February 03, 2011, 02:55:06 PM »
... but you also have to account for the viewport block that exists in every layout...

I don't think you do with an ssget call as I thought it will only select 'primary' objects, but will have to test to be certain.
Open a brand new drawing, if a viewport exists, erase it and try this:

Code: [Select]
(sslength (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)))))
It should return 1.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Search for viewport ...
« Reply #7 on: February 03, 2011, 03:03:20 PM »
; error: bad argument type: lselsetp nil

Apologies, that was in Model :ugly:

Yes, it does return 1 - I stand happily corrected :D
« Last Edit: February 03, 2011, 03:06:57 PM by Lee Mac »

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Search for viewport ...
« Reply #8 on: February 03, 2011, 03:15:35 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Search for viewport ...
« Reply #9 on: February 03, 2011, 03:28:07 PM »
; error: bad argument type: lselsetp nil

Apologies, that was in Model :ugly:

Yes, it does return 1 - I stand happily corrected :D
It can still be deleted, but as far as I've seen, when you restart the drawing, it's recreated.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Hangman

  • Swamp Rat
  • Posts: 566
Re: Search for viewport ...
« Reply #10 on: February 03, 2011, 03:37:18 PM »
; error: bad argument type: lselsetp nil

Apologies, that was in Model :ugly:

Yes, it does return 1 - I stand happily corrected :D
It can still be deleted, but as far as I've seen, when you restart the drawing, it's recreated.

In the Layout Elements under the Display tab in Options, you can take the check mark out of the "Create viewport in new layouts".
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Search for viewport ...
« Reply #11 on: February 03, 2011, 03:46:34 PM »
; error: bad argument type: lselsetp nil

Apologies, that was in Model :ugly:

Yes, it does return 1 - I stand happily corrected :D
It can still be deleted, but as far as I've seen, when you restart the drawing, it's recreated.

In the Layout Elements under the Display tab in Options, you can take the check mark out of the "Create viewport in new layouts".

True, but the Paperspace Viewport will always exist  :wink:

Hangman

  • Swamp Rat
  • Posts: 566
Re: Search for viewport ...
« Reply #12 on: February 03, 2011, 03:51:47 PM »
; error: bad argument type: lselsetp nil

Apologies, that was in Model :ugly:

Yes, it does return 1 - I stand happily corrected :D
It can still be deleted, but as far as I've seen, when you restart the drawing, it's recreated.

In the Layout Elements under the Display tab in Options, you can take the check mark out of the "Create viewport in new layouts".

True, but the Paperspace Viewport will always exist  :wink:

Perhaps I am missing something.  I deleted the tab that has a viewport, right click on the tab and pick new layout.  I now have two layouts and no viewport.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Search for viewport ...
« Reply #13 on: February 03, 2011, 03:53:09 PM »
; error: bad argument type: lselsetp nil

Apologies, that was in Model :ugly:

Yes, it does return 1 - I stand happily corrected :D
It can still be deleted, but as far as I've seen, when you restart the drawing, it's recreated.

In the Layout Elements under the Display tab in Options, you can take the check mark out of the "Create viewport in new layouts".

True, but the Paperspace Viewport will always exist  :wink:

Perhaps I am missing something.  I deleted the tab that has a viewport, right click on the tab and pick new layout.  I now have two layouts and no viewport.
What happens when you paste this into the commadline?

Code: [Select]
(sslength (ssget "_X" '((0 . "VIEWPORT"))))
This one should be correct: http://www.theswamp.org/index.php?topic=36979.msg419724#msg419724
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Search for viewport ...
« Reply #14 on: February 03, 2011, 03:59:40 PM »
Note that the Paperspace Viewport won't be visible, but is inherent to each layout - you can check this by iterating through the collection of objects in the Layout Block Object.