LISP crashing AutoCAD

LISP crashing AutoCAD

Anonymous
Not applicable
1,029 Views
4 Replies
Message 1 of 5

LISP crashing AutoCAD

Anonymous
Not applicable

Hello,

I am working on a LISP program to run when opening a drawing to enforce standards. I found the following code (on a forum post; I can't remember where) to provide some control over whether or not the program runs if opening a new drawing or opening a previously saved drawing. I want it to automatically run when opening a new drawing and prompt user to decide whether or not they want it to run when opening a previously saved drawing.

 

I had a long (illness filled) weekend and can't remember where I left off, but when I went load this particular selection of code, the command line repeated "Initializing..." over and over again and AutoCAD then crashed. When I opened AutoCAD again it would crash once the program automatically ran at start-up. I removed the following code from the program, so I'm assuming the problem is somewhere in here:

 

(if (= (getvar 'dwgtitled) 0)
  (c:standardsetup)
  ((initget "Continue Cancel")
    (if (= "Continue" (getkword "\nRun Standard Set-up? [COntinue/CAncel] <Cancel>: "))
      (if (or c:standardsetup (and (load "C:\\Users\\mcfoster1\\AppData\\Roaming\\Autodesk\\C3D 2019\\enu\\Support\\Individual LISP Routines\\Standard Set-up.lsp" nil) c:standardsetup))
	(c:standardsetup)
	(princ "\nc:standardsetup could not be defined.")
	)
      )
    )
  )

Is there something in this selection of code that I have wrong that would cause this crashing loop?

 

Thank you!

Michael

0 Likes
Accepted solutions (1)
1,030 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Okay, so I may have figured it out... BUT I have a new problem, well not new, but one that I forgot about.

 

(if (= (getvar 'dwgtitled) 0)
  (c:standardsetup)
  ((initget "Continue Cancel")
    (if (= "Continue" (getkword "\nRun Standard Set-up? [COntinue/CAncel] <Cancel>: "))
      (if (or c:standardsetup (and (load "C:\\Users\\mcfoster1\\AppData\\Roaming\\Autodesk\\C3D 2019\\enu\\Support\\Individual LISP Routines\\Standard Set-up.lsp" nil) c:standardsetup))
	(c:standardsetup)
	(princ "\nc:standardsetup could not be defined.")
	)
      )
    )
  )

I'm guessing that the "\nc:standardsetup..." doesn't quite work. I changed it to "\nStandard setup..."

 

So the other problem is that when I try it out and it prompts to "Continue" or "Cancel", it says "Invalid option keyword". Does this mean I can only have "Yes" and "No"? Or am I missing something?

 

Thank you!

Michael

0 Likes
Message 3 of 5

johnyDFFXO
Advocate
Advocate
Accepted solution

@Anonymous wrote:

Hello,

I am working on a LISP program to run when opening a drawing to enforce standards. I found the following code (on a forum post; I can't remember where) to provide some control over whether or not the program runs if opening a new drawing or opening a previously saved drawing. I want it to automatically run when opening a new drawing and prompt user to decide whether or not they want it to run when opening a previously saved drawing.

 

I had a long (illness filled) weekend and can't remember where I left off, but when I went load this particular selection of code, the command line repeated "Initializing..." over and over again and AutoCAD then crashed. When I opened AutoCAD again it would crash once the program automatically ran at start-up. I removed the following code from the program, so I'm assuming the problem is somewhere in here:

 

(if (= (getvar 'dwgtitled) 0)
  (c:standardsetup)
  (progn (initget "Continue Cancel")
    (if (= "Continue" (getkword "\nRun Standard Set-up? [COntinue/CAncel] <Cancel>: "))
      (if (or c:standardsetup (and (load "C:\\Users\\mcfoster1\\AppData\\Roaming\\Autodesk\\C3D 2019\\enu\\Support\\Individual LISP Routines\\Standard Set-up.lsp" nil) c:standardsetup))
	(c:standardsetup)
	(princ "\nc:standardsetup could not be defined.")
	)
      )
    )
  )

Is there something in this selection of code that I have wrong that would cause this crashing loop?

 

Thank you!

Michael


I think that prompt part is working as it is... but for sake of insurance you should have the same capitals at (initget) as at prompt.

And also- it could be a bit simper:

(initget "Continue")
(if (getkword "\nRun Standard Set-up? [Continue] <cancel>: ")
  "Go"
  "Stop"))

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

Great! The "(progn..." was what I needed!

So I have another issue... I'm trying to get this code to actually run and not load when opening a drawing. This is what I have right now.

(load "C:\\Users\\mcfoster1\\AppData\\Roaming\\Autodesk\\C3D 2019\\enu\\Support\\Individual LISP Routines\\Standards.lsp")

(defun c:enforcement ()
  (if (= (getvar 'dwgtitled) 0)
    (c:standardsetup)
    (progn (initget "Continue Cancel")
      (if (= "Continue" (getkword "\nRun Standard Set-up? [Continue/CAncel] <Cancel>: "))
	(c:standardsetup)
	(alert "\nStandards Not Loaded")
	)
      )
    )
  )
(c:enforcement)

I didn't have the "(defun c:enforcement ()" originally, but I thought that turning it into a defined function would allow me to run it with "(c:enforcement)".

Any advice with this?

 

Thanks,

Michael

0 Likes
Message 5 of 5

Anonymous
Not applicable

Well, it seems to be working now. I'm not sure why it wouldn't originally and now it does, but I came into work, started up AutoCAD and the lisp loaded AND ran when I opened a new drawing.

 

Thanks for the help!

Michael