gregmorris234 Posted November 22, 2018 Posted November 22, 2018 Hello there, I recently came across a LISP routine which looks to do what I need. So I have a dwg set up with sheet names 'Plot-*' and layers set up as 'Plot-*' too. What I want the LISP to do is VP freeze all 'Plot-*' layers, and then thaw the plot number of which the sheet corresponds to. For example on sheet with name Plot-1 I want all 'Plot-*' layers to freeze but Plot-1 to stay thawed. Code: (defun c:layfrz (/ _ctab num ss) (setq _ctab (getvar 'CTAB)) (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") ) (setq num (substr x (+ (vl-string-position (ascii "-") x) 2))) (command "_.vplayer" "_F" "*|*Plot-*" "_S" ss "" "_T" (strcat "*|*Plot-" num "*") "_S" ss "" "") (command "_.pspace") ) ) ) (setvar 'CTAB _ctab) (command "_.qsave") (princ) ) I did try modifying the code from that forum post by replacing Sheet_ with Plot- and (ascii "-") but I kept getting an error return or the tool just wouldn't work. Is there anyone that could help? Greg Quote
Emmanuel Delay Posted November 27, 2018 Posted November 27, 2018 Like this? (defun c:layfrz (/ _ctab num ss) (setq _ctab (getvar 'CTAB)) (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 ;; freeze everything containing "Plot-" (command "_.vplayer" "_F" "*Plot-*" "_S" (ssname ss 0) "" "") ;; Thaw the correct layers (command "_.vplayer" "_T" (strcat "*Plot-" num "*") "_S" (ssname ss 0) "" "") (command "_.pspace") )) ) ) ) (setvar 'CTAB _ctab) (command "_.qsave") (princ) ) freeze_by_layout.dwg 1 Quote
gregmorris234 Posted November 29, 2018 Author Posted November 29, 2018 This is great. It's almost doing what I want to do except it's thawing all the layers that have the first number in. For example for the 'Plot-1' sheet it's thawing the 'Plot-1' layer, however it is also thawing 'Plot-100' to 'Plot-199'. I'm not sure what I'd need to change to get it right, but yes it's very near to what I need. Thank you very much for your help! G Quote
Emmanuel Delay Posted November 30, 2018 Posted November 30, 2018 (edited) 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) ) Edited November 30, 2018 by Emmanuel Delay 1 Quote
gregmorris234 Posted December 5, 2018 Author Posted December 5, 2018 Emmanuel, This works an absolute treat. It's now doing what I wanted and freezing off the correct plot layers by sheet title and I'm very thankful for your help. It's also freezing off all other layers (ie. layers that don't start with 'Plot-*') but that was an issue I could skirt around with the VPLAYER command so it's not a major issue. But again, thank you very much for your help. Your annotated LISP code has really given me an insight and knowledge of how the code works and hopefully soon I will be able to edit these properly myself. G 1 Quote
gregmorris234 Posted April 14, 2020 Author Posted April 14, 2020 Would anyone be able to advise how to modify the code? I'd like to change the layer name but when I did it, and modified the numbers as the string length changed but I couldn't get it to work. Additionally, do I need to change anything so that the code freezes XREF layers? Greg Quote
gregmorris234 Posted April 14, 2020 Author Posted April 14, 2020 This LISP does not seem to work at all now, even with the existing layer naming. It seems to get stuck at the VPLAYER command after going into the viewport. Baffling as the code hasn't changed at all and I've kept to all the same drawing principles! Argh, very frustrating. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.