Save Layerstate of Model Space and Paper Space including all Viewports

Save Layerstate of Model Space and Paper Space including all Viewports

Lineabove
Collaborator Collaborator
422 Views
1 Reply
Message 1 of 2

Save Layerstate of Model Space and Paper Space including all Viewports

Lineabove
Collaborator
Collaborator

Below is my version of a lisp which will cycle through a drawing and save the Layerstate of:

Model Space

Paper Space Layouts

Paper Space Layout Viewports

 

To assist me, I have added the following to my Acaddoc.lsp

(setvar 'modemacro "VP $(getvar,CVPORT)")

Which was allways display the number of the Current Viewport in the status bar.

 

Any comments or suggestions to optimize the code are welcome.

 

 

;; Prepared by standing on the shoulders of others...
;; Many thanks to Henrique (hmsilva) for the bulk of this code
;; Many thanks to unknown author for the balance of this code
 
(defun c:LSSVPorts (/ _ctab layst nt i ss vp)
(Command "Model")
(Command "ZOOM" "E")
 
;; MODEL SPACE LAYERSTATE
(IF (layerstate-has (getvar "CTAB")) (layerstate-delete (getvar "CTAB")))
  (COMMAND "-LAYER" "A" "S" (getvar "CTAB") "" "" "")
  (princ)
 
  (setq _ctab (getvar 'CTAB))
  (foreach x (layoutlist)
    (setvar 'CTAB x)
    (if (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2))
      (command "_.pspace")
    )
    (command "_.zoom" "_E")
 
;;PAPERSPACE LAYOUT TAB LAYERSTATES
     (IF (layerstate-has (getvar "CTAB")) (layerstate-delete (getvar "CTAB")))
  (COMMAND "-LAYER" "A" "S" (getvar "CTAB") "" "" "")
  (graphscr)
  (princ)
 
    (if (setq ss (ssget "_X"
   (list '(0 . "VIEWPORT")
         '(-4 . "!=")
         '(69 . 1)
         (cons 410 x)
   )
   )
 )
      (repeat (setq i (sslength ss))
 (setq hnd (ssname ss (setq i (1- i)))
       ent (entget hnd)
       vp  (cdr (assoc 69 ent))
 )
 (if (> vp 1)
   (progn
     (if
       (not
  (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2))
       )
        (command "_.mspace")
     )
     (setvar 'CVPORT vp)
     (setq layst (strcat x " VP " (itoa vp)))
 

;;PAPERSPACE LAYOUT TAB VIEWPORT LAYERSTATES
      (IF (layerstate-has layst) (layerstate-delete layst))
  (COMMAND "-LAYER" "A" "S" layst "" "" "")
  (graphscr)
    (princ)
 
   )
 )
      )
    )
    (command "_.pspace")
  )
  (setvar 'CTAB _ctab)
  (princ)
)
0 Likes
423 Views
1 Reply
Reply (1)
Message 2 of 2

Lineabove
Collaborator
Collaborator

Sightly modifed so that you will end in the Tab you started in, rather than being forced to Model Space.

 

 

 

 

;; Prepared by standing on the shoulders of others...
;; Many thanks to Henrique (hmsilva) for the bulk of this code
;; Many thanks to unknown author for the balance of this code
 
(defun c:LSSVPorts (/ _ctab layst nt i ss vp)
  (setq _ctab (getvar 'CTAB))
  (foreach x (layoutlist)
    (setvar 'CTAB x)
    (if (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2))
      (command "_.pspace")
    )
    (command "_.zoom" "_E")
 

;;PAPERSPACE LAYOUT TAB LAYERSTATES
     (IF (layerstate-has (getvar "CTAB")) (layerstate-delete (getvar "CTAB")))
  (COMMAND "-LAYER" "A" "S" (getvar "CTAB") "" "" "")
  (graphscr)
  (princ)
 
    (if (setq ss (ssget "_X"
   (list '(0 . "VIEWPORT")
         '(-4 . "!=")
         '(69 . 1)
         (cons 410 x)
   )
   )
 )
      (repeat (setq i (sslength ss))
 (setq hnd (ssname ss (setq i (1- i)))
       ent (entget hnd)
       vp  (cdr (assoc 69 ent))
 )
 (if (> vp 1)
   (progn
     (if
       (not
  (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2))
       )
        (command "_.mspace")
     )
     (setvar 'CVPORT vp)
     (setq layst (strcat x " VP " (itoa vp)))
 

;;PAPERSPACE LAYOUT TAB VIEWPORT LAYERSTATES
      (IF (layerstate-has layst) (layerstate-delete layst))
  (COMMAND "-LAYER" "A" "S" layst "" "" "")
  ;;(graphscr)
    (princ)
   )
 )
      )
    )
    (command "_.pspace")
  )
 
(Command "Model")
(Command "ZOOM" "E")
 
;; MODEL SPACE LAYERSTATE
(IF (layerstate-has (getvar "CTAB")) (layerstate-delete (getvar "CTAB")))
  (COMMAND "-LAYER" "A" "S" (getvar "CTAB") "" "" "")
   (graphscr)
    (princ)
 
(setvar 'CTAB _ctab)
  (princ)
)
0 Likes