freeze_by_layout.dwg
Okay, plan B. All layers one by one
Notice: now integers are evaluated. So leading zeros will be disregarded, for example 001 = 1
;; for example: layername = "Plot-123ABC" => return = 123. prefix is chopped of (the "Plot-"),
;; then atoi returns the longest possible integer of the string, and chopps off everything on the right of that (the "ABC")
(defun get_number (layername prefixlength / )
(atoi (substr layername (+ 1 prefixlength)))
)
(defun all_layers ( / a layers)
(setq layers (list))
(while (setq a (tblnext "LAYER" (null a)))
(setq layers (append layers (list (cdr (assoc 2 a)))))
)
layers
)
(defun c:layfrz (/ _ctab num ss layers layer oldosmode oldcmdecho)
;; suppress messages in the command
(setq oldosmode (getvar "osmode"))
(setq oldcmdecho (getvar "cmdecho"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(setq _ctab (getvar 'CTAB))
(setq layers (all_layers))
(foreach x (layoutlist)
(setvar 'CTAB x)
(if (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 x) (cons -4 "!=") (cons 69 1))))
(progn
(if (not (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2)))
(command "_.mspace")
)
(if (= "Plot-" (substr x 1 5)) (progn
(setq num (substr x 6)) ;; "Plot-" is 5 characters, so the number stars at 6
(foreach layer layers
(if
(= (atoi num) (get_number layer 5))
(command "_.vplayer" "_T" layer "_S" (ssname ss 0) "" "") ;; Thaw
(command "_.vplayer" "_F" layer "_S" (ssname ss 0) "" "") ;; Freeze
)
)
(command "_.pspace")
))
)
)
)
(setvar 'CTAB _ctab)
(command "_.qsave")
;; set variables back
(setvar "osmode" oldosmode)
(setvar "cmdecho" oldcmdecho)
(princ)
)