I have been using the following lsp routine for years with AutoCAD 2006. I believe it was given to me by someone from these forums. It worked perfectly with AutoCAD 2006.
I recently upgraded to AutoCAD 2014. The lsp now works most of the time but not all the time. Why would it not work sometimes? It is in the start up suite so it should load when CAD is launched. In fact, it does load but it doesn't work with every file.
part of the problem is I'm not a programmer, just a guy who knows how to load lsp routines...
Thank you.
;;-------------------=={ Layer Director }==-------------------;;
;; ;;
;; Uses a Command Reactor to automatically set the active ;;
;; layer upon the user invoking a command. ;;
;; ;;
;; Layer settings are stored in the list at the top of the ;;
;; program. The first entry in the list is the command on ;;
;; which the reactor will trigger, it may use wildcards. ;;
;; The second entry is the name of the layer to be set when ;;
;; the command is called, this layer will be created if ;;
;; not present in the active drawing. ;;
;; ;;
;; The Director is enabled upon loading this program. ;;
;; It may be manually switched ON and OFF by typing ;;
;; 'LDON' and 'LDOFF' respectively at the command line. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2012 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Version 1.1 - 24-04-2012 ;;
;;------------------------------------------------------------;;
;;------------------------------------------------------------;;
;; Layer Data ;;
;; ======================================================== ;;
;; ;;
;; Populate this list with commands for which the current ;;
;; layer should be changed. ;;
;; ;;
;; The first item is the name of a command that will cue a ;;
;; layer change. The command name should be the full command ;;
;; name, not an alias. This command name is not ;;
;; case-sensitive and may use wildcards. ;;
;; ;;
;; e.g. "[DM]TEXT,TEXT" will cue a layer change for the ;;
;; Text, DText and MText commands. ;;
;; ;;
;; e.g. "*LEADER" will cue a layer change for the Leader, ;;
;; QLeader and MLeader commands. ;;
;; ;;
;; The second item is the name of the Layer to be set to ;;
;; current when the command is called. This layer will be ;;
;; created if not present in the active drawing. ;;
;;------------------------------------------------------------;;
(setq *LayerDirector-LayerData*
'(
;; COMMAND LAYER NAME ;;
("[DM]TEXT,TEXT" "TEXT" )
("DIM*,*LEADER" "DIM")
("*VPORT*" "DEFPOINTS" )
)
)
;;------------------------------------------------------------;;
;; Print Command Debug Mode [ t / nil ] ;;
;; ======================================================== ;;
;; ;;
;; If set to T the program will print the command name when ;;
;; a command is called. This is useful when determining ;;
;; the correct command name to use in the Layer Data list. ;;
;;------------------------------------------------------------;;
(setq *PrintCommand* nil)
;;------------------------------------------------------------;;
;; Commands: [ LDON / LDOFF ] ;;
;; ======================================================== ;;
;; ;;
;; Use these to manually turn the Layer Director on & off. ;;
;;------------------------------------------------------------;;
(defun c:LDON nil (LM:LayerDirector t ))
(defun c:LDOFF nil (LM:LayerDirector nil))
;;------------------------------------------------------------;;
(defun LM:LayerDirector ( on / reactor )
(setq reactor
(car
(vl-member-if
(function
(lambda ( reactor )
(eq "LayerDirector" (vlr-data reactor))
)
)
(cdar (vlr-reactors :vlr-command-reactor))
)
)
)
(if on
(if reactor
(if (vlr-added-p reactor)
(princ "\nLayer Director already running.")
(progn
(vlr-add reactor)
(princ "\nLayer Director Enabled.")
)
)
(progn
(vlr-command-reactor "LayerDirector"
'(
(:vlr-commandwillstart . LM:LayerDirector-Set)
(:vlr-commandended . LM:LayerDirector-Reset)
(:vlr-commandcancelled . LM:LayerDirector-Reset)
(:vlr-commandfailed . LM:LayerDirector-Reset)
)
)
(princ "\nLayer Director Enabled.")
)
)
(if reactor
(progn
(vlr-remove reactor)
(princ "\nLayer Director Disabled.")
)
(princ "\nLayer Director not running.")
)
)
(princ)
)
(defun LM:LayerDirector-Set ( reactor params / layer tmp )
(if
(and
(setq params (strcase (car params)))
(setq layer
(cadar
(vl-member-if
(function
(lambda ( item )
(wcmatch params (strcase (car item)))
)
)
*LayerDirector-LayerData*
)
)
)
(setq tmp (LM:LayerDirector-CreateLayer layer))
(zerop (logand 1 (cdr (assoc 70 tmp))))
)
(progn
(setq *LayerDirector-OldLayer* (getvar 'clayer))
(setvar 'clayer layer)
)
)
(if *PrintCommand* (print params))
(princ)
)
(defun LM:LayerDirector-Reset ( reactor params / tmp )
(if
(and
(not (wcmatch (strcase (car params)) "U,UNDO"))
*LayerDirector-OldLayer*
(setq tmp (tblsearch "LAYER" *LayerDirector-OldLayer*))
(zerop (logand 1 (cdr (assoc 70 tmp))))
)
(progn
(setvar 'clayer *LayerDirector-OldLayer*)
(setq *LayerDirector-OldLayer* nil)
)
)
(princ)
)
(defun LM:LayerDirector-CreateLayer ( name )
(cond
( (tblsearch "LAYER" name))
( (entmake
(list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
(cons 2 name)
'(70 . 0)
)
)
)
)
)
;;------------------------------------------------------------;;
(vl-load-com)
(LM:LayerDirector t) ;; Director will run when loaded.
(princ)
;;------------------------------------------------------------;;
;; End of File ;;
;;------------------------------------------------------------;;
Can't find what you're looking for? Ask the community or share your knowledge.