These lines of code do a magnificent job of explaining mapcar....(place glowing light bulb here)
Excellent to hear Bruce!
It just goes to show - after all the extensive explanations on the topic of
mapcar, it just takes a simple few lines of code for it to click.
My only question that I've noticed when seeing this use of mapcar is where are the users original settings stored?
You've actually answered this yourself in your dissection of the code
(setq val (mapcar 'getvar var)) ;set a variable 'val' which holds the values when mapcar applies the "getvar" command to each item in the 'var' list
As you can see, the original values for each system variable are stored in the list 'val' (for
VALues).
If the program is modifying attreq to do it's duty, shouldn't attreq be put back to what it's value was before the program was initiated ? j/w, typically heard this is good coding practice and perhaps just a quick and dirty routine was given, still- trying to be clear on the topic!
Indeed! - All programs should return the user's AutoCAD environment to exactly how they found it, resetting any modified system variables to their original values.
My posted example resets these values on line 69, and also in the error handler on line 12 (in case the program encounters an error after the system variables have been modified, but not yet reset).
So let me be clear myself! I'm not asking this to point out any inadequacies in the given code as any code given is a gem and should be respected, ie. not everyone can do it, it's time consuming, and it's very useful for the person intended for. That's a heck of a combination. I did, however, ask because i'm genuinely wondering if there's a mapcar method to save the sys vars beforehand, or is it handled in another fashion when this setup is used.....or...? Thanks! that's why i'm asking.
Certainly - don't worry about raising these questions!
I appreciate the flattering compliments, but I am the first to admit that I am certainly not infallible and will make mistakes from time to time. If you believe you have found a mistake in my code, or feel there is a better way to tackle a problem, I welcome you to post your questions & constructive criticism!
Then, if the reported issue is already addressed by the code (as in this case), I will usually offer an explanation as to why the issue is already covered by the code, thus aiding the understanding of the person raising the issue and of the community as a whole; and, if the issue needs to be addressed, the code will be improved as a result, and I may also learn something new.
It's a win-win!
Here is a simple example to show how the variables are reset in Lee's code:
Many thanks Ron for providing an explanation & covering whilst I was preoccupied - I've been incredibly busy these past few weeks and just haven't been able to check-in here as often as I used to.
Lee Mac, Thank you! except for the error trapping the routine is working perfectly. Thank you also for the error trapping suggestions, that is quite a bit for me to study over to make sure I understand what you have written.
You're welcome! - Take as long as you need to study the code I have posted, and I will be happy to answer any questions about its operation as my time permits.
Besides the error trapping, my CAD manager has one more thing he wants me to add to the routine. His request was to have the mark number fill in with a sequential number each time the routine is ran
Yes - this is indeed possible - consider the following code (again entirely untested!):
;; Example program written for Swamp thread:
;; http://www.theswamp.org/index.php?topic=45993.0
;; by Lee Mac 2014-01-16
(defun c:tlmk
( / *error* blk dch dcl dwg mark_n sel title_n val var
)
(setq dwg
"N:/Tuterj/AutoLISP/Working/TitleMark-field.dwg" ;; Block to insert dcl "N:/tuterj/AutoLISP/Working/TL-MK_Scale_add.dcl" ;; DCL file
)
)
)
)
)
)
)
)
(princ (strcat "\n" dcl
" file contains an error, dialog could not be loaded.")) )
( t
(set_tile "mark_n" "(setq mark_n (itoa tlmk:num))") (alert "Please enter a value for the mark_n tile.") )
(alert "Please enter a value for the title_n tile.") )
)
)
)
(if (setq sel
(LM:
ssget "\nSelect viewport: " '
("_+.:E:S" ((0 .
"VIEWPORT"))))) (setq var '
(cmdecho insunits attreq
) )
(princ "\nSpecify insertion point for block: ") (vl-cmdf "_.-insert" blk
"_S" 1.0 "_R" 0.0 "\\" "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
">%).CustomScale \\f \"%sn\">%"
)
mark_n
)
)
)
)
)
)
)
;; ssget - Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;; msg - [str] selection prompt
;; arg - [lst] list of ssget arguments
)
;; ObjectID - Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems
(defun LM:objectid
( obj
) )
)
)
)
(LM:objectid obj)
)
;; Active Document - Lee Mac
;; Returns the VLA Active Document Object
(LM:acdoc)
)
Anyway thank you again for your time and help. I greatly appriciate it. I owe you a couple of pints!
You're welcome - I'm happy to offer my assistance
Lee