Hello,
I used to think that it is not a good idea to use global variables in lisp codes and variables should be local to their corresponding commands. Now I've completely changed my mind. I use global variables a lot. But to avoid making a big mess, all these global variables are named "glb::cmd_*", where cmd is the name of the command and "*" can be anything. The primary reason for me to use global variables is to make user input a little easier. If a user repeatly uses a command, his previous input can be used as the default value for later ones. Or in some cases, user will not need to be asked for that input. I have a command to clean these global variables when necessary.
(defun C:00 (/ strName)
(prompt "\nScanning for variables...")
(princ)
(foreach sym (atoms-family 0)
(setq strName (strcase (vl-symbol-name sym)))
(if (wcmatch strName "GLB::*")
(set sym nil)
)
)
(prompt " Done.")
(princ)
)
I'm thinking of triggering this when double-click on an empty spot occurs.
If a variable needs to be shared among open drawings, I use vl-bb-ref and vl-bb-set.
What's your thought? Thank you.
Kelie