TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Guest on September 18, 2007, 10:16:13 AM

Title: Select each viewport on each layout tab (if there is a viewport)
Post by: Guest on September 18, 2007, 10:16:13 AM
I've got some drawings that I'm trying to update with a little proggy.  The proggy will cycle through each layout tab, unlock any viewports it finds, then (and this is where I'm having a problem) jump inside of each viewport and then turn off/on/thaw/freeze some specific layers.

A little guidance please??
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: T.Willey on September 18, 2007, 11:04:32 AM
See this thread. (http://www.theswamp.org/index.php?topic=10992.0)

But if you are going into each layout, then you can just filter out the viewport with the id of 0   1, that is the paper space viewport.

Edit: Change what is stricken out and what is red.
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: Guest on September 18, 2007, 11:11:10 AM
Cool... Next question.  Once I've got the list of viewports, how can I get into it?  MSPACE appears to only work on the last active viewport?
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: T.Willey on September 18, 2007, 11:17:56 AM
Cool... Next question.  Once I've got the list of viewports, how can I get into it?  MSPACE appears to only work on the last active viewport?
Each viewport Id will correspond to the value of the 'cvport' system variable.  So if the viewport has an id of 5, then change the variable 'cvport' to 5, and you should be in the viewport you want.
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: Marco Jacinto on September 18, 2007, 11:21:26 AM
You can use the Cvport system variable or the vla-get-ActivePViewport property of the Document object, just issue MSpace command or property before.

Try this:
Code: [Select]
(SETQ ssvp (SSGET "_X"
  '((0 . "VIEWPORT") (-4 . ">") (69 . 1))
   )
)
(REPEAT (SETQ ct (SSLENGTH ssvp))
  (SETQ ct (1- ct)
ename (SSNAME ssvp ct)
entData (ENTGET ename)
Layout (CDR (ASSOC 410 entData))
  )
  (SETVAR "ctab" Layout)
  (VL-CMDF "MsPace")
  (SETVAR "cvport" (CDR (ASSOC 69 entData)))
  (ALERT
    (STRCAT "Viewport number "
    (ITOA (CDR (ASSOC 69 entData)))
    " is now current"
    )
  )
)

Saludos
Marco Jacinto
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: T.Willey on September 18, 2007, 11:25:02 AM
Marco is right with his code.  I gave you bad info in my first post.  The paper space viewport's id is 1, so filter out 1 and you should get all the viewports within the paper space.
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: Guest on September 18, 2007, 11:35:35 AM
Marco is right with his code.  I gave you bad info in my first post.  The paper space viewport's id is 1, so filter out 1 and you should get all the viewports within the paper space.

All respect I had for you just went right out the window!   :wink:

Thanks guys!  Much appreciated!!
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: T.Willey on September 18, 2007, 11:42:20 AM
Marco is right with his code.  I gave you bad info in my first post.  The paper space viewport's id is 1, so filter out 1 and you should get all the viewports within the paper space.

All respect I had for you just went right out the window!   :wink:

Thanks guys!  Much appreciated!!
I blame it on the first post in the morning...... Yea that will work.   :angel:
Glad you got what you wanted.
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: Marco Jacinto on September 18, 2007, 12:14:54 PM
Glad it wors

Saludos
Marco Jacinto
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: ronjonp on September 18, 2007, 12:17:53 PM
You could also pull all the necessary info from the viewports and combine them into a list to manipulate.

Code: [Select]
(foreach l (layoutlist)
  (setvar 'ctab l)
)
(setq ss (ssget "x" '((0 . "VIEWPORT") (-4 . ">") (69 . 1))))
(if ss
  (progn
    (setq ss (mapcar 'cadr (ssnamex ss)))
    (mapcar
      '(lambda (x)
(setq lst (cons (list x
       (cdr (assoc 410 (entget x)))
       (cdr (assoc 69 (entget x)))
)
lst
   )
)
       )
      ss
    )
    (foreach vp lst
      (setvar 'ctab (nth 1 vp))
      (command "._mspace")
      (setvar 'cvport (nth 2 vp))
      (command "._pspace")
    )
  )
)

Where lst would hold info something like this:


 [1] (<Entity name: 7efec0f8> "Layout2" 3)
 [2] (<Entity name: 7efec118> "Layout2" 4)
 [3] (<Entity name: 7efec138> "Layout2" 5)
 [4] (<Entity name: 7efec1d8> "Layout2" 6)
 [5] (<Entity name: 7efec1f8> "Layout2" 7)


Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: T.Willey on September 18, 2007, 12:26:43 PM
Doing it that way Ron you would not get all the correct (non-paper space viewports) viewports.  Read the other thread that I posted a link to and you will see why.  To long to explain here. :-)
Title: Re: Select each viewport on each layout tab (if there is a viewport)
Post by: ronjonp on September 18, 2007, 12:42:49 PM
That's right...I guess the only way my code would get a correct list is to cycle through the tabs prior to collecting. (or use CABS code)  :-)