The Jester Posted November 21 Posted November 21 (edited) CAD Version: Carlson Survey 2025 w/ IntelliCAD 12.1 Experience: Novice With a new drawing, I can get the below LISP to run once... ; ADJOINER LABELS (defun c:AT () (SETQ CL (GETVAR "CLAYER")) (command "LAYER" "S" "PROP_ADJ_TXT" "") (setq DS (getvar 'dimscale)) (SETQ TW (* DS 2.5)) (setq pt (getpoint "\nPick label location: ")) (setq l1 (getstring T "\nType line 1 of 3 adjoiner info: ")) (setq l2 (getstring T "\nType line 2 of 3 adjoiner info: ")) (setq l3 (getstring T "\nType line 3 of 3 adjoiner info: ")) (COMMAND "MTEXT" "_non" Pt "J" "MC" "S" "L100" "W" TW l1 l2 l3 "") (SETVAR "CLAYER" CL) (C:MDO)) but when I attempt to run it a second time (and so on), I receive the following error: LISP Error in function: lsp_defatom_ex(): Duplicate key Uknown exception thrown. :error#0variable definition failed :error#0 I can close the drawing and reopen it, and again, it will allow me to run the LISP once, then fail all the times after. The "duplicate key" within the error leads to believe the LISP is being cached in memory; but I don't know if that is the case, and if so, how do I clear it. Edited November 22 by fuccaro adding CODE tags Quote
The Jester Posted November 22 Author Posted November 22 (edited) On 11/22/2024 at 5:55 AM, devitg said: @The Jester what (C:MDO)) Stand or mean for ? I was shown this by a coworker that wrote LISP routines for AutoCAD 2004. He didn't explain how it works or what it stands for, but many of his LISPs ended this way. He has since passed. I have used the following as well, with the results being the same (it works once, then fails with the same error until the drawing is closed and reopened). ; ADJOINER LABELS (defun c:AT () (SETQ CL (GETVAR "CLAYER")) (command "LAYER" "S" "PROP_ADJ_TXT" "") (setq DS (getvar 'dimscale)) (SETQ TW (* DS 2.5)) (setq pt (getpoint "\nPick label location: ")) (setq l1 (getstring T "\nType line 1 of 3 adjoiner info: ")) (setq l2 (getstring T "\nType line 2 of 3 adjoiner info: ")) (setq l3 (getstring T "\nType line 3 of 3 adjoiner info: ")) (COMMAND "MTEXT" "_non" Pt "J" "MC" "S" "L100" "W" TW l1 l2 l3 "") (SETVAR "CLAYER" CL) (princ) ) Edited November 23 by SLW210 Added Code Tags!! Quote
Steven P Posted November 22 Posted November 22 (edited) A lot of errors "runs once but afterwards there is an error" are due to localising variables. A local variable is one that is only used in that routine, global is saved away and can be used on any routine while that drawing is open. To reduce these define the variable as local for example: (defun c:AT ( / CL DS) localises your variables CL and DS - their values at the end of the routine won't appear in other LISPs or the next time you run this one. Second comment is the last line (C:MDO) is calling another LISP to run - I suspect the problem might be in there, do you have a copy of that you an share? Last comment, you might want to put in a check that the layer, Prop_Adj_Txt exists, create it if it doesn't (something to do that should be easy to find online) Edited November 22 by Steven P Quote
The Jester Posted November 22 Author Posted November 22 1 hour ago, Steven P said: A lot of errors "runs once but afterwards there is an error" are due to localising variables. A local variable is one that is only used in that routine, global is saved away and can be used on any routine while that drawing is open. To reduce these define the variable as local for example: (defun c:AT ( / CL DS) localises your variables CL and DS - their values at the end of the routine won't appear in other LISPs or the next time you run this one. Second comment is the last line (C:MDO) is calling another LISP to run - I suspect the problem might be in there, do you have a copy of that you an share? Last comment, you might want to put in a check that the layer, Prop_Adj_Txt exists, create it if it doesn't (something to do that should be easy to find online) Thank you Steven. The addition of the ( / CL DS) resolved the issue. As for the second comment, I started the current batch of routines from scratch, and thus far, have not referred any routines to MDO...with that said, I changed the end of this routine back to MDO and it still works. I am not advanced enough to understand how or why, but it works. I have been doing some research online, but the answer still eludes me. As for the final comment, I have a list of all the available layers that I keep open and refer to often. Again, thank you for solution. 1 Quote
SLW210 Posted November 23 Posted November 23 Please use Code Tags for your code. (<> in the editor toolbar) Quote
Steven P Posted November 23 Posted November 23 Excellent, LISP is a frustrating journey at times but can be rewarding too when something works right (and better when it saves enough time to grab an extra coffee break in the day) Always good to get feedback if something works out right (many don't, we assume it is working after due to no more questions) - keep asking if you need more advice and help For (C:MDO) - you might have a LISP file from your ex colleague which is automatically loaded and contains this. Lee Mac has a routine getsyntax which will list all routines contained within a file (Lee Mac is an excellent resource, whether it is a complete routine or work out how they work in other functions). See also he threat "Command Table Creating" from earlier today - I've posted a LISP in there, if all the LISP files are in a single location this should also find the routine also. However if MDO doesn't cause any errors then that is just a nice to know thing. Quote
The Jester Posted November 25 Author Posted November 25 On 11/23/2024 at 7:45 AM, SLW210 said: Please use Code Tags for your code. (<> in the editor toolbar) I will do so going forward. Thank you for the information. Quote
The Jester Posted November 25 Author Posted November 25 On 11/23/2024 at 8:48 AM, Steven P said: Excellent, LISP is a frustrating journey at times but can be rewarding too when something works right (and better when it saves enough time to grab an extra coffee break in the day) Always good to get feedback if something works out right (many don't, we assume it is working after due to no more questions) - keep asking if you need more advice and help For (C:MDO) - you might have a LISP file from your ex colleague which is automatically loaded and contains this. Lee Mac has a routine getsyntax which will list all routines contained within a file (Lee Mac is an excellent resource, whether it is a complete routine or work out how they work in other functions). See also he threat "Command Table Creating" from earlier today - I've posted a LISP in there, if all the LISP files are in a single location this should also find the routine also. However if MDO doesn't cause any errors then that is just a nice to know thing. I will agree, frustrating, yet rewarding. I have noticed the same in other forums; people ask for assistance, then ghost the community, not replying whether the solution was from someone within the group, or something entirely different. I will do what I can to respond...though sometimes slightly behind like this response now. LoL. I have been looking into Lee Mac, and will be utilizing his tools to aid in my progression. I will check out the LISP you created, as well as the "getsyntax" from Lee Mac. I really am curious as to how the MDO is functioning...I will update if / when I find the reasoning or cause. Thank you again for the help and suggestions. Quote
The Jester Posted December 10 Author Posted December 10 On 11/23/2024 at 8:48 AM, Steven P said: Excellent, LISP is a frustrating journey at times but can be rewarding too when something works right (and better when it saves enough time to grab an extra coffee break in the day) Always good to get feedback if something works out right (many don't, we assume it is working after due to no more questions) - keep asking if you need more advice and help For (C:MDO) - you might have a LISP file from your ex colleague which is automatically loaded and contains this. Lee Mac has a routine getsyntax which will list all routines contained within a file (Lee Mac is an excellent resource, whether it is a complete routine or work out how they work in other functions). See also he threat "Command Table Creating" from earlier today - I've posted a LISP in there, if all the LISP files are in a single location this should also find the routine also. However if MDO doesn't cause any errors then that is just a nice to know thing. So, I figured out the MDO mystery...it is a draw order that I had buried in my earlier files. I just remember my predecessor saying to always use it at the end of any command...so I have. Thank you again for the assistance. 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.