The following is a routine that I have found very useful to use. There is
only one problem. I can't figure out how to come back to the layer that the
command was issued in. It stays in the text or dim. layer. Any suggestions
would be appreciated.
;VLR_COMMAND.lsp courtesy Peter Jamtgaard 2003
; Vlr Command is a function that will switch the active layer in a drawing.
; The reactor checks the command that is starting and if it recognizes it
; it will switch to a specified layer. If the layer doesn't exist it will
; create it with the color, linetype, and plottable setting provided.
; To load and run this program add the lines (load
"vlr_command")(c:vlr_command)
; to your acaddoc.lsp or another autoloading lisp routine.
(defun C:AVLR_COMMAND ()
(vl-load-com)
(vlr-editor-reactor nil '((:vlr-commandwillstart . COM1)))
)
(vla-get-Layer setq cl (getvar "nlayer"))
(defun COM1 (CALL CALLBACK / COMLAYLST)
; Examples of Command vs Layer
; List of corrusponding commands layers color linetype
plottable
(setq COMLAYLST (list (list "qdim" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimlinear" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimaligned" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimordinate" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimradius" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimdiameter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimangular" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimbaseline" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcontinue" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimqleader" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "tolerance" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcenter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dtext" "TEXT" 3 "continuous"
:vlax-true)
(list "mtext" "TEXT" 3 "continuous"
:vlax-true)
(list "text" "TEXT" 3 "continuous" :vlax-true)
; Add your own command layer lists here....
)
)
(foreach N COMLAYLST
(if (= (strcase (car CALLBACK)) (strcase (car N)))
(progn
(make_layers (cadr N)
(caddr N)
(cadddr N)
(car (cddddr N))
)
(setq n1 n)
(vla-put-activelayer
(vla-get-activedocument
(vlax-get-acad-object)
)
(vlax-ename->vla-object
(tblobjname "LAYER" (cadr N))
)
)
)
)
)
(prin1)
)
(setvar "nlayer" cl)
; Make layers using activeX
(defun MAKE_LAYERS (LAY_NAM COLOR LTYPE PLOTL / LAYOBJ LAYSOBJ LTYPESOBJ)
(setq CDWGOBJ (vla-get-activedocument
(vlax-get-acad-object)
)
LAYSOBJ (vla-get-layers CDWGOBJ)
)
(if (not (tblobjname "layer" LAY_NAM))
(vl-catch-all-error-p
(vl-catch-all-apply 'vla-add (list LAYSOBJ LAY_NAM))
)
)
(setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
(if (not (tblobjname "ltype" LTYPE))
(progn
(setq LTYPESOBJ (vla-get-linetypes CDWGOBJ))
(vla-load LTYPESOBJ LTYPE (findfile "acad.lin"))
(vlax-release-object LTYPESOBJ)
)
)
(vla-put-layeron LAYOBJ :vlax-true)
(if (/= (strcase (vla-get-name LAYOBJ)) (strcase (getvar "clayer")))
(vla-put-freeze LAYOBJ :vlax-false)
)
(vla-put-lock LAYOBJ :vlax-false)
(vla-put-color LAYOBJ COLOR)
(vla-put-linetype LAYOBJ LTYPE)
(vla-put-plottable LAYOBJ PLOTL)
)
(prin1)