I have this routine that I got from the AUGI Exchange, I have sucessfully modified the lisp to allow me to pick the layer extension, the problem is:
When I use the lisp, I want the layers to be created with the same attributes (colors, line types) and then at the end to freeze them. My problem is, I have no Idea how to create new layers with the same attributes, and I have no Idea how to combine a string and a variable to do a search through layers and find all layers ending with the specified layer extension.
Here is the Lisp routine, any help would be greatly appreciated if you wish, please compare it with the original lisp routine on AUGI Exchange it might assist you in seeing what I have modified:
Code:
;;; Created by Karl Browning
;;; kbrowning@chasebrass.com
;;; 16 May 2003
;;;
;;; This function is used to select an object(s), figure out what layer it is on,
;;; make a new layer based on the old one with "-Freeze" appended, change the object
;;; to the new layer, then freeze layers *-Freeze. I made this to clean up some vendor
;;; prints without losing the data.
;;;
;;; Feel free to modify the lisp, just send me a copy of it when you are done.
(defun c:la->freeze
(/ sset counter item LayerName NewLayerName Layerext)
(vl-load-com)
(initerr) ;Load error trapping
(setvar "cmdecho" 0)
(command "undo" "m")
(setq Layerext (strcase (getstring "\nEnter layername extension ")))
(setq sset (ssget)) ;get selection set
(setq counter 0) ;set the counter
(repeat (sslength sset) ;count number of entities and loop
(setq item (ssname sset counter) ;extract the entity name
item (vlax-ename->vla-object item)
;convert to a vl object
LayerName (vla-get-layer item) ;get the object's layer
) ;_ end of setq
(if (= (TBLSEARCH "Layer" (strcat LayerName Layerext)) nil)
;check for "layer"-Freeze
(progn
(setq NewLayerName (strcat LayerName Layerext))
;if not there, create it
(command ".layer" "new" NewLayerName "")
) ;_ end of progn
(setq NewLayerName (strcat LayerName Layerext))
) ;_ end of if
(vla-put-layer item NewLayerName)
(setq counter (1+ counter))
) ;_ end of repeat
(princ)
(command ".layer" "freeze" *Layerext "")
; (load "c:/Program Files/Autocad 2005/express/acetlayr.lsp")
; (command "layfrz" (entget (entlast)) "")
(setq sset nil)
(reset)
(princ)
) ;_ end of defun
(defun error ()
(prompt "\nGlobal Error Trap Loaded")
(princ)
)
;;;*=================================================================================
(defun initerr ()
(setq oldlayer (getvar "clayer")
oldsnap (getvar "osmode")
oldpick (getvar "pickbox")
temperr *error*
*error* trap
)
(princ)
)
;;;*=================================================================================
(defun trap (errmsg)
(command nil nil nil)
(if (not (member errmsg '("console break" "Function Cancelled"))
)
(princ (strcat "\nError: " errmsg))
)
(command "undo" "b")
(setvar "clayer" oldlayer)
(setvar "menuecho" 0)
(setvar "highlight" 1)
(setvar "osmode" oldsnap)
(setvar "pickbox" oldpick)
(princ "\nError Resetting Environment ")
(terpri)
(setq *error* temperr)
(princ)
)
;;;*=================================================================================
(defun reset ()
(setq *error* temperr)
(setvar "clayer" oldlayer)
(setvar "menuecho" 0)
(setvar "highlight" 1)
(setvar "osmode" oldsnap)
(setvar "pickbox" oldpick)
(princ)
)
;;;*=================================================================================
(princ)