AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Can you remember in Newsletter No 2001-02 when I included an article on "Controlling Layering Standards" by Frank Zanders? This routine was written using VBA. Well here's a similar application I wrote using Visual Lisp and Reactors :

;CODING STARTS HERE
(prompt " \nLoad Only....Do NOT Run...")
(vl-load-com)

;***********************************************************************
(vlr-command-reactor
nil '((:vlr-commandWillStart . startCommand)))
(vlr-command-reactor
nil '((:vlr-commandEnded . endCommand)))
(vlr-command-reactor
nil '((:vlr-commandCancelled . cancelCommand)))
;*************************************************************************
(defun startCommand (calling-reactor startcommandInfo /
thecommandstart)
(setq OldLayer (getvar "CLAYER"))
(setq thecommandstart (nth 0 startcommandInfo))
(cond
((= thecommandstart "TEXT") (setvar "CLAYER" "4"))
((= thecommandstart "MTEXT") (setvar "CLAYER" "4"))
((= thecommandstart "DTEXT") (setvar "CLAYER" "4"))

((= thecommandstart "HATCH") (setvar "CLAYER" "6"))
((= thecommandstart "BHATCH") (setvar "CLAYER" "6"))
);cond
(princ)
);defun
;**********************************************************************

(defun endCommand (calling-reactor endcommandInfo /
thecommandend)
(setq thecommandend (nth 0 endcommandInfo))
(cond
((= thecommandend "TEXT") (setvar "CLAYER" OldLayer))
((= thecommandend "MTEXT") (setvar "CLAYER" OldLayer))
((= thecommandend "DTEXT") (setvar "CLAYER" OldLayer))
((= thecommandend "HATCH") (setvar "CLAYER" OldLayer))
((= thecommandend "BHATCH") (setvar "CLAYER" OldLayer))

);cond
(princ)
);defun
;*****************************************************************************
(defun cancelCommand (calling-reactor cancelcommandInfo /
thecommandcancel)
(setq thecommandcancel (nth 0 cancelcommandInfo))
(cond
((= thecommandcancel "TEXT") (setvar "CLAYER" OldLayer))
((= thecommandcancel "MTEXT") (setvar "CLAYER" OldLayer))
((= thecommandcancel "DTEXT") (setvar "CLAYER" OldLayer))
((= thecommandcancel "HATCH") (setvar "CLAYER" OldLayer))
((= thecommandcancel "BHATCH") (setvar "CLAYER" OldLayer))
);cond
(princ)
);defun
;*********************************************************
(princ)
;CODING ENDS HERE

=======================================================
When a user adds Text or Hatch to the drawing, the layer will automatically change to Layer "4" or Layer "6" respectively. When the command is completed, or cancelled, the user is returned to the original Layer he was on before he started the command. Save the file as "LayMan.lsp", BUT please remember, that as this routine contains reactors, you must only Load it and NOT Run it. If you want to use this routine on a permanent basis, you'll have to ensure that it is loaded at startup. There is also no checking to ensure that the layers exist, are frozen, switched off, etc. and no other form of error checking. I've got to leave something for you to do!!!

The AutoLisp/Visual Lisp/VBA Resource Website

Copyright © 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website