Older AutoLISP not working in AutoCAD 2019

Older AutoLISP not working in AutoCAD 2019

SeeZur
Participant Participant
1,608 Views
12 Replies
Message 1 of 13

Older AutoLISP not working in AutoCAD 2019

SeeZur
Participant
Participant

Greetings,

I have this older LISP that worked on older AutoCAD versions but once upgraded to AutoCAD 2019 it is no longer working.

What is causing this to happen?

Appreciate any help with this.

Thank you

 

;------------------------------------------------------------------------------
;  DIA.LSP - Draws lines on both sides of the selected centerline
;               using half the given diameter value.

(princ "Please wait ... Loading ")
(defun C:DIA ()

;  Function to change the properties of the LAST (newest) item created.

(defun FIXUP ()
  (setq ss (entget (entlast)))
  (setq ss (subst (cons 8 (getvar "clayer")) (assoc 8 ss) ss))  ; LAyer
  (setq ss (subst (cons 6 "BYLAYER") (assoc 6 ss) ss))          ; LType
  (setq ss (subst (cons 62 256) (assoc 62 ss) ss))              ; Color
  (entmod ss)
)  ; finish FIXUP

(setq os (getvar "osmode")) (setvar "osmode" 0)
(setq e (entsel "Select centerline: ")) (setvar "osmode" os)
(if (/= e nil)
  (if (= "LINE" (cdr (assoc 0 (setq L (entget (car e))) )))
    (progn
      (setq cont t)
      (while cont
        (initget (+ 2 4)) (setq d (getreal "\nEnter diameter: "))
        (if (= d nil)
          (setq cont nil)
          (progn
            (setq p1 (cdr (assoc 10 L)) p2 (cdr (assoc 11 L)) )
            (setq s1 (polar p1 (+ (angle p1 p2) (/ pi 2.0)) 1.0))
            (setq s2 (polar p1 (- (angle p1 p2) (/ pi 2.0)) 1.0))
            (setq bm (getvar "blipmode") ce (getvar "cmdecho")
                  os (getvar "osmode"))
            (setvar "blipmode" 0) (setvar "cmdecho" 0) (setvar "osmode" 0)
            (command "Offset" (/ d 2.0) e s1 "") (FIXUP)
            (command "Offset" (/ d 2.0) e s2 "") (FIXUP)
            (setvar "blipmode" bm) (setvar "cmdecho" ce) (setvar "osmode" os)
          )    ; finish progn
        )      ; finish if = d
      )        ; finish while
    )          ; finish progn
    (prompt "\nERROR: Selected item MUST be a LINE.")
  )            ; finish if = "LINE"
)              ; finish if /= e

(princ)
)


 

0 Likes
Accepted solutions (1)
1,609 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant

@SeeZur wrote:

.... it is no longer working. ....


That is never enough information.  Does it not load?  Does it load, but the command name isn't recognized?  Is the command name recognized, but it doesn't do anything at all?  Does it do some of what's wanted, but not everything?  How far does it get?  Are there any messages?  Etc., etc.

Kent Cooper, AIA
Message 3 of 13

SeeZur
Participant
Participant

Appreciate the reply and input, apologize for the lack of information, will get that gathered and added here.

Thank you

0 Likes
Message 4 of 13

pendean
Community Legend
Community Legend
@SeeZur Your posted LISP works fine: perhaps you forgot it is limited to only selecting LINE object types to work?
Or perhaps you need to zoom in very close (or zoom out very far) to see the effects of your digits entry?

Or Do you not even have it loaded and are wanting to know how to load it to run in AutoCAD2019?

OR... are you now using the LT version of AutoCAD 2019 and haven't known about the no-lisp option in there?

TIA
Message 5 of 13

SeeZur
Participant
Participant

So it will load into AutoCAD with start up suit without showing error.

But when typing out command it is not recognized and that is as far as this goes.

0 Likes
Message 6 of 13

SeeZur
Participant
Participant

Appreciate the reply,

Using AutoCAD 2019 full version, It loaded up in the start up suite without any error message, just when using the command itself it does not recognize it. 

Loaded it up on AutoCAD 2018 full version and it worked as intended.

And yes correct, only meant to be used with lines, lisp is used to make a diameter bore from center line.

0 Likes
Message 7 of 13

pendean
Community Legend
Community Legend
Accepted solution

What does "... it does not recognize it...." mean? Expand the commandline to be taller than 1-line and see what AutoCAD is trying to explain.

You can also just drag and drop the LSP file itself on top of your open DWG file in R2019 then type DIA to try and execute it: what does that do? Again, watch the commandline.

Perhaps in R2019 you have an add-on or something else called DIA? Like I said, your LISP here works fine in R2019-2020-2021-2022 so... not sure how to help you remotely without more info from you when you get a chance.

Message 8 of 13

hak_vz
Advisor
Advisor

@SeeZur 

Here you have edited code with some features that are missing in original code, although original code was working good. Command is renamed to BD so that it don't coincide with some other function, as @pendean  has mentioned in post no 7.

;------------------------------------------------------------------------------
;  BD.LSP - Draws lines on both sides of the selected centerline
;               using half the given diameter value.
(princ "Please wait ... Loading ")
(defun C:BD ( / *error* fixup os e L cont d p1 s1 s2 bm ce os )
	;  Function to change the properties of the LAST (newest) item created.
	(vl-load-com)
	(defun *error* (msg)
		(mapcar 'setvar '("blipmode""cmdecho""osmode")(list bm ce os))
		(and msg (not (wcmatch (strcase msg) "*CANCEL*,*QUIT*,*BREAK*,*EXIT*"))(princ (strcat "\nError: " msg)))
		(princ)
	)
	(defun pick_line (msg)
		(setq e (car(entsel msg)))
		(if (and (not e)(member(getvar 'Errno) '(7 52)))
			(pick_line msg)
			e
		)
	)
	(defun fixup ()
		(setq 
			ss (entget (entlast))
			ss (subst (cons 8 (getvar "clayer")) (assoc 8 ss) ss)  ; LAyer
			ss (subst (cons 6 "BYLAYER") (assoc 6 ss) ss)          ; LType
			ss (subst (cons 62 256) (assoc 62 ss) ss)             ; Color
		)
		(entmod ss)
	)  ; finish fixup
	(setvar "osmode" 0)
	(setq 
		os (getvar "osmode")
		bm (getvar "blipmode")
		ce (getvar "cmdecho")
		e (pick_line "\nSelect centerline: ")
	
	)
	(if (= "LINE" (cdr(assoc 0 (setq L(entget e)))))
		(progn
			(setq
				cont t
				p1 (cdr (assoc 10 L))
				p2 (cdr (assoc 11 L))
			)
				(while cont
					(initget (+ 2 4)) 
					(setq d (getreal "\nEnter diameter: "))
					(if (null d)
						(setq cont nil)
						(progn
							(setq 
								s1 (polar p1 (+ (angle p1 p2) (/ pi 2.0)) 1.0)
								s2 (polar p1 (- (angle p1 p2) (/ pi 2.0)) 1.0)
								bm (getvar "blipmode")
								ce (getvar "cmdecho")
								os (getvar "osmode")
							)
							(mapcar 'setvar '("blipmode" "cmdecho" "osmode")'(0 0 0))
							(command "_.offset" (/ d 2.0) e s1 "") (fixup)
							(command "_offset" (/ d 2.0) e s2 "") (fixup)
							(mapcar 'setvar '("blipmode""cmdecho""osmode")(list bm ce os))
						)    ; finish progn
					)      ; finish if = d
				)        ; finish while
		)          ; finish progn
		(prompt "\nERROR: Selected item MUST be a LINE.")
	)            ; finish if = "LINE"	
	(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 9 of 13

SeeZur
Participant
Participant

What was meant by "... it does not recognize it...." is that in start up suite it shows the LISP loaded then in a new drawing I start typing in the command, which in this case is "DIA", but it does not show it as an option or command.

See below: (Note the highlighted "STAT" portion is what AutoCAD has suggested for autocomplete but has not been typed out) 

lopezcs24_0-1644538801158.png

In current setup the commands show up next to the cursor and it has a drop down list of possible commands with the current string of letters.

 

Tried the drag and drop method after removing from Startup Suite and restarting AutoCAD.

This did work, and command works as it should, but do need to load up every time.

This then would raise the question, what would cause it to not load through startup suite when it does with drag and drop?

 

As far as for add-in or other LISPs nothing else loaded with DIA or similar command.

 

P.S.

For checking add-ins/plugins in AutoCAD used APPLOAD command to check, but list is tight and can't capture in one screen shot. Is there a place to check where it can be expanded? Tried selecting all to copy paste into another.

Guessing can only list by manually scrolling down writing down or stitch screen shots together to make a full list?

lopezcs24_1-1644539789235.png

*Note: Took this example screen shot from AutoCAD 2018, but is the same in 2019.

 

0 Likes
Message 10 of 13

SeeZur
Participant
Participant

Greetings,

Appreciate this new LISP.

 

Removed the DIA LISP and restarted AutoCAD.

Loaded up BD LISP with drag and drop method, as suggested by @pendean in message 7, to test out and it worked.

Restarted AutoCAD and loaded BD LISP into startup suite.

Restarted AutoCAD so that BD LISP would load through startup suite, but command would not appear when typing out command as an option like the original DIA lisp.

0 Likes
Message 11 of 13

Kent1Cooper
Consultant
Consultant

This is from Help about the Startup Suite:

 

Note: Starting with AutoCAD 2014-based products, the custom applications added to the Startup Suite must be placed in a trusted location; trusted locations are specified by the TRUSTEDPATHS system variable.

 

Do you have it in a trusted location?  Also:

 

These are the applications that are loaded each time you start AutoCAD.

 

which is not the same as things that are loaded by acaddoc.lsp, which will happen in every drawing you start or open, not just when you start AutoCAD.  Sometimes it has seemed that things in the Startup Suite are loaded in all drawings, but I haven't experimented extensively, and it's not described that way.

Kent Cooper, AIA
Message 12 of 13

SeeZur
Participant
Participant

Appreciate the response,

Interesting, will try this out to see if that might be the issue.

 

On separate note,

we tried loading the original DIA lisp, noted in the original post, on a colleague's computer with AutoCAD 2019 full version and he as well had them same issues described. So it will work when dragging and dropping in but not with startup suite. So it seems that AutoCAD 2019 startup suite and something with this lisp are causing the issue.

 

Will update after trying this out to see if trusted path can fix this.

0 Likes
Message 13 of 13

annie.webster
Community Visitor
Community Visitor

I'm having a similar issue.  It wasn't recognizing the command but now it's giving an error. "Automation Error. Problem in Loading VBA. 

0 Likes