TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: FengK on March 24, 2006, 04:47:14 AM
-
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
-
Kelie
Using global vars is a necessary thing in some code. My own rules:
- Default values for user prompts -> global vars
- Default values relating to drawing -> dictionary
- Default values relating to application -> registry (or ini file)
-
Kelie
Using global vars is a necessary thing in some code. My own rules:
- Default values for user prompts -> global vars
- Default values relating to drawing -> dictionary
- Default values relating to application -> registry (or ini file)
..and Default values for one ACAD-Session ..blackboard namespace -> vl-bb-ref / vl-bb-set functions, but i also prefer registry for this implementation
-
Kelie
Using global vars is a necessary thing in some code. My own rules:
- Default values for user prompts -> global vars
- Default values relating to drawing -> dictionary
- Default values relating to application -> registry (or ini file)
I do something similar, but need to do more dictionaries. My globals or way overkill, but I'm still learning.
Gary
-
Using global vars is a necessary thing in some code. My own rules:
- Default values for user prompts -> global vars
- Default values relating to drawing -> dictionary
- Default values relating to application -> registry (or ini file)
Thanks Jürg. I think I need to take a look at dictionary and registry now.
-
Welcome... :-)
You may check CADmium's recommendation also:
..and Default values for one ACAD-Session ..blackboard namespace -> vl-bb-ref / vl-bb-set functions, but i also prefer registry for this implementation