Is there a standard (good practice) way of handling optional parameters for functions?
---
The idea is: the user either
- selects an entity (entsel, ssget, ...) , fills in a value (getint, getstring, ...)
OR
- presses enter, then an other procedure takes over, or a default value gets set.
One concrete example, is a post I just answered, to insert (Lamp) blocks evenly spread in a room.
http://www.cadtutor.net/forum/showthread.php?88364-block-spacing-lisp&p=667270#post667270
Let's say this function is used 5 times in 1 dwg, and mostly with the same blockname, and the same number of rows and columns. It would be useful for the user if the function inserts the previous value if the user presses Enter
Some remarks:
1.
The (getstring) function never returns nil.
2.
In your c:test function you are overwriting global variables making your testfunction useless.
3.
There is nothing wrong with global variables. Most programmers will use them in this situation. But there can be name conflicts.
I think that Lee Mac's tutorial is the best out there for how to prompt with a default option http://www.lee-mac.com/promptwithdefault.html. How I often do it when I am doing something like an entsel is
Just one more little example I'm using right now. I have a paper copy of a layout that has to be redrawn in AutoCad. I measure a known distance with a known dimension to calculate a scale factor and from there on the routine returns the actual distance for every distance I measure until I cancel or enter 0 to recalibrate the scale factor. It stores this factor in a variable (rescale-factor) that is valid during the current drawing session.