;; NAME
;; Layer Settings
;;
;; SYNOPSIS
;; Load a previous saved layer file.
;;
;; DESCRIPTION
;; This application will allow you to load previous saved layers
;; (name, color, line type, and state) to the current drawing. If
;; the layers do not exist they will be created using the
;; settings in the file. If the layer name already exists in the
;; drawing, those settings will not be updated -- this is to
;; allow for custom, per drawing, layer overrides-.
;; //-- SEE CHANGE LOG --//
;;
;; This procedure starts upon load into AutoCAD.
;;
;; To save the current drawings layers use:
;; (process-on-drawing (save-layer-list-to-file))
;; A file with the current drawings file name, with the `.la'
;; suffix will be saved to the current drawings location.
;;
;; NOTES
;; | This procedure was published (posted) to offered as a starting
;; O | point for your own layer state restore procedure. Although it
;; U | can be used as is, the procedure can be expanded to offer a
;; T | better overall layer creator application for your company
;; | standards. Currently I do not have any time to spend working
;; | on this application.
;;
;; D | My overall objective was to create a fast way for me to load
;; A | up layer settings for my CAD users. I have run several
;; T | benchmarks on the procedures I used in this application and as
;; E | a whole as well. I tested this application's time for creating
;; D | 10,000 layers in a blank drawing and this app took approximately
;; | 0.23 seconds to preform that operation.
;;
;; AUTHOR
;; John (Se7en) Ka
;;
;; VERSION
;; 1.0.ave
;;
;; CHANGE LOG
;; 1.0.0 Orig issue
;; 05.20.08
;; 1.0.1 Revised to handle plot/noplot setting
;; (dxf code 290)
;; Closed layer file once done reading
;; 05.27.08
;; 1.0.2 Removed parsing of drawings layer list to
;; names ...making it faster.
;; New time for creating 10,000 layers was 1.36 seconds
;; 05.28.08
;; 1.0.3 Added the ability to modify layers already in dwg which
;; are different the ones found in the layer file.
;; 1.0.4 Added the ability to load and handle linetypes not in
;; drawing or located in .lin file in search path
;; 07.22.08
;;
;;
;; //-- CAUTION (After version 1.0.4) --//
;; since the addition of the layer and linetype over rides this
;; application has become very sloppy and needs to go thru a re-write
;; I plan on re-writing this applicaion when I have more time.
;;
;;
;; Last Updated: 07.22.08 9:32:29 AM
;; //-- BEGIN SUPPORT PROCEDURES --//
(defun process
-on
-drawing
( process
) ;; a simple `hook' to run a process
;; (if (= (getvar 'DWGTITLED) 1)
;; "Drawing not saved"
;; )
)
(defun save
-layer
-list
-to
-file
( / x f fp
) ;; retrieve all layers from dwg dict and save
;; to a file. file saved where drawing is located
)
(defun get
-list
-from
-file
( name
/ fp lst read
-file
-into
-list ) ;; general file reader
;; given a file name this procedure will read the contents
;; into a list
lst
)
(defun get
-drawing
-dictionary
-list ( what
/ x lst
) ;; retrieve a list of drawing dictionary entries
;; given a list of raw dic entries this proced
;; will report entity names
nil
;; return list of items found in dwg but different from list
x))
ls) )
(defun remove
-uncomon
-names
( ls
) ;; return the items that are not in drawing
;; (member x dwg-layer-list)
))
x))
ls) )
(defun get
-value
( val lst
) ;; shortcut for returning value in assoc list
(defun files
-p
( path pattern
) ;; files-p
;;
;; Returns a list of all the files in a given path
;; with a given search pattern. If a nill pattern
;; to search for is not given, defaults to ``*.*''.
;;
;; Ex:
;; (files-p "C:\\" nil)
;;
;; => returns all files in directory specified.
;;
;; By: John (7) K
;;
(
nil
path ; a
pattern ; e
) )
(defun strParse
(aStr delim
/ strList pos
) ;; Find the postition where the delimiter first shows up.
;; create a list of the fist substring (up untill the delimiter)
;; Skip over the delimiter and grab the rest of the string,
;; Set that as the new string
)
)
;; //-- END SUPPORT PROCEDURES --//
todo
-layer
-list timer layers
-to
-modify
ltype
-file
-locations file
-layer
-list ltype
-locations dwg
-ltype
-name
-list )
;;;
;;;(defun c:laf ( / dwg-layer-list dwg-layer-name-list
;;; todo-layer-list timer layers-to-modify
;;; ltype-file-locations file-layer-list
;;; ltype-locations dwg-ltype-name-list
;;; )
dwg
-layer
-list (process
-on
-drawing '
(get
-drawing
-dictionary
-list "LAYER")) ;; build a list of layers in current drawing
(process
-on
-drawing '
(get
-drawing
-dictionary
-list "LTYPE"))) ;; build a list of litetype names loaded in dwg
ltype-file-locations
;; itterate thru the entire search path to look for .lin files
(setq tmp
-str
(files
-p x
"*.lin")) x
"\\"
(strparse
(getvar "ACADPREFIX") ";") )) ltype-locations
;; a list of lists for the lietypes and their locations
;; ( <path>+<file> ( <ltype> <ltype> ... ))
(get-list-from-file x)
)
)
)
ltype-file-locations
)
'
read (get
-list
-from
-file
;;; (getfiled "Layer file" "" "la" 0)
))
;; get the layers from the file (layers to impliment)
;; ;; set up a timer
todo
-layer
-list (remove
-uncomon
-names file
-layer
-list) ;; build a list of layers that need to be created.
)
;; parse out the already defined common layers
;;
;; create layers not in drawing already
;;
;; TODO: Add Linetype support -- inline
;; create the layers
;; do not opperate on null entries.
lt
(command
-s
"_.linetype" "_load" lt
(car x
) "") ;; remake the drawing ltype list
(process-on-drawing
'
(get
-drawing
-dictionary
-list "LTYPE")))) );_ end progn
);_ end if
);_ end lambda
ltype-locations)
;; another search level incase we still coulnt find lt.
"\nLinetype for Layer: "
(get-value 2 x)
" Not found, using continuous instead."))
)
(cons 6 (get
-value
6 x
))) )
)
plot
((get-value 290 x)
(cons 290 (get
-value
290 x
))) '(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
(cons 70 (get
-value
70 x
)) (cons 62 (get
-value
62 x
)) plot
lt
);_ end list
);_ end entmake
);_ end progn
);_ end if
)
)
(setq dwg
-layer
-list (process
-on
-drawing '
(get
-drawing
-dictionary
-list "LAYER")) layers
-to
-modify
(build
-modify
-list file
-layer
-list) ;; build a list of layers that need to be modified.
)
;;
;; Update or change layers that do not have properties
;; listed in layer file
;;
;; TODO: Add linetype support -- inline
'
(lambda ( x
/ lt plot layer
) ;; do not opperate on null entries in list
;; get the layer from the dwg dict.
;; we are going to modify several of the drawing layer props at once
;; the dxf codes can be found at the end of the mapcar function call
;; if we are on key 290 (ploting flag)
(set 'plot
(if (get
-value key x
) 0 1)) ;; determine if the layer value has the 290 entry;
;; if not return 1 (plot able) if it does return 0
;; mod the layer list
)
((get-value key layer)
;; other wise just mod the layer list
'(6 62 70 290) )
;; make modifications
);_ end progn
);_ end if
)
layers-to-modify
)
"\n;; Process took "
(rtos (/ (- (getvar "millisecs") timer
) 1000.0) 2 4) " seconds."))
)
; (laf "blah\\blah\\Company-Layers.la")