The Buzzard Posted March 27, 2009 Posted March 27, 2009 Here is an additional feature, Before it puts in the layers, The program saves the current layer, Then puts in the new layers, unless they are already in the drawing and then set the original layer back to current. Give it a shot. ;;;///////////////////////////////////////////////////////////////// (defun c:SLS () ;Define function (setq ROL (getvar "clayer")) ;Set ROL to current layer (SET_LAYER) ;Goto SET_LAYER Function (RESET_ORIGINAL_LAYER) ;Goto RESET_ORIGINAL_LAYER Function (princ) ;Exit quietly ) ;End of define function ;;;///////////////////////////////////////////////////////////////// (defun SET_LAYER () ;Define function (CREATE_LAYER "Const" "1" "CONTINUOUS") ;Goto CREATE_Layer Function, Layer Name, Color, LineType (CREATE_LAYER "Steel" "2" "CONTINUOUS") ;Goto CREATE_Layer Function, Layer Name, Color, LineType (CREATE_LAYER "Dimension" "4" "CONTINUOUS") ;Goto CREATE_Layer Function, Layer Name, Color, LineType (CREATE_LAYER "Hidden" "1" "HIDDEN") ;Goto CREATE_Layer Function, Layer Name, Color, LineType (CREATE_LAYER "Text" "7" "CONTINUOUS") ;Goto CREATE_Layer Function, Layer Name, Color, LineType (CREATE_LAYER "Welds" "6" "CONTINUOUS") ;Goto CREATE_Layer Function, Layer Name, Color, LineType (CREATE_LAYER "Ref" "8" "CONTINUOUS") ;Goto CREATE_Layer Function, Layer Name, Color, LineType ) ;End define function ;;;///////////////////////////////////////////////////////////////// (defun CREATE_LAYER (NLAY CLR LT / LAY FRZ) ;Define function, Declare variables and arguments (setq LAY (tblsearch "layer" NLAY)) ;Search drawing to find layer (if ;If the following returns true (not LAY) ;Layer not in drawing (command "_.layer" "m" NLAY "c" CLR "" "lt" LT "" "") ;Layer command ~ make new layer with color and linetype (progn ;Then do the following (setq FRZ (cdr (assoc 70 LAY))) ;Variable FRZ is frozen layer (if (= FRZ 65) ;Layer frozen from last edit (progn ;Then do the following (command "_.layer" "t" NLAY "") ;Thaw new layer if frozen (command "_.layer" "s" NLAY "") ;Set new layer ) ;End progn (otherwise...) (command "_.layer" "s" NLAY "") ;Set new layer ) ;End if ) ;End progn (otherwise...) ) ;End if ) ;End define function ;;;///////////////////////////////////////////////////////////////// (defun RESET_ORIGINAL_LAYER () ;Define function (command "_.layer" "s" ROL "") ;Layer command ~ Reset original layer ) ;End define function ;;;///////////////////////////////////////////////////////////////// Just to mention: This is the part in the code that prevents overwriting existing layers. It searches the drawing for the layer names. If the layer is not in the drawing, Then proceed to make the layer. (setq LAY (tblsearch "layer" NLAY)) ;Search drawing to find layer Quote
Lee Mac Posted March 29, 2009 Posted March 29, 2009 Or could be simplified to: (defun c:layupd (/ vlst ovar laylist) (setq vlst '("CMDECHO" "CLAYER") ovar (mapcar 'getvar vlst)) (setvar "CMDECHO" 0) (setq laylist '( ("LAYER1" "4" "CONTINUOUS") ("LAYER2" "3" "HIDDEN") ;; List Layers, Colours & Linetypes )) (foreach lay laylist (if (not (tblsearch "LAYER" (car lay))) (command "-layer" "m" (car lay) "C" (cadr lay) (car lay) "") (command "-layer" "C" (cadr lay) (car lay) "")) (if (tblsearch "LTYPE" (caddr lay)) (command "-layer" "LT" (caddr lay) (car lay) "") (princ (strcat "\n" (caddr lay) " Linetype could not be found!")))) (mapcar 'setvar vlst ovar) (princ)) (c:layupd) 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.