Lisp not working when loading with ACAD.lsp

Lisp not working when loading with ACAD.lsp

raceharder
Enthusiast Enthusiast
640 Views
10 Replies
Message 1 of 11

Lisp not working when loading with ACAD.lsp

raceharder
Enthusiast
Enthusiast

I have a lisp that is being loaded by ACAD.lsp.  The lisp does not work after startup.  It returns "Exited:  bad argument type: FILE nil " when using the command to run the lisp.  If I appload the lisp, it works fine.  Can anyone give me some ideas or suggestions on what I might try to fix this?

 

Any help/advice/suggestions is/are greatly appreciated.

 

RH

0 Likes
641 Views
10 Replies
Replies (10)
Message 2 of 11

ronjonp
Advisor
Advisor

It would help if you posted the code you're having issue with.

0 Likes
Message 3 of 11

raceharder
Enthusiast
Enthusiast

What code would you like to see?  The code for the non working lisp or the code for ACAD.lsp?  

Again, this works when it is apploaded.  It just will not work after autocad loads a file until I appload.  He is the code for the non functioning lisp:

 

;; This code takes the last 3 digits of the filename
;; and puts them on the tag SHT_NO_1 on tb supplied
;; by Ford
;; It writes the FILE_NAME tag from the
;; system variable dwgname
;; The rest of the variables are written
;; out from a sample sheet into a file
;; called ttlblk.txt written in the homedir of
;; the drawing file


;;for kits added 4/17/08
(defun C:NG_KFTBIN ( / unit)
(setq unit "1A10")
(FTB UNIT)
)

 

(defun C:NGK ( / unit)
(setq unit "1A10")
(FTB UNIT)
)

 

;;for pneumatics
(defun C:NG_PFTBIN ( / unit)
(setq unit "1A7")
(FTB UNIT)
)

(defun C:NGP ( / unit)
(setq unit "1A7")
(FTB UNIT)
)

;; for water
(defun C:NG_WFTBIN ( / unit)
(setq unit "1A8")
(FTB UNIT)
)

(defun C:NGW ( / unit)
(setq unit "1A8")
(FTB UNIT)
)


;; SHORTCUT FOR LEE
(defun C:NG_IN ()
(print " in in")
(C:FTBIN)
)
;; for electric

(defun C:NGFTBIN ( / unit)
(PRINT "IN FTBIN")
(setq unit "1A5")
(FTB UNIT)
)


(defun FTB (UNIT / dwgnme homedir desclgth dwglen startpnt dwgnm len_dwgnm)


(setq dwgnme (getvar "DWGNAME"))
(setq homedir (getvar "DWGPREFIX"))

(setq ttlfil (strcat homedir "NGtitleblk.txt")
f (open ttlfil "r")
)
(print "dwgname is ")(print dwgnme)
(print "homedir is ")(print homedir)
(print "ttfil is ")(print ttlfil)
; ;(setq len_dwgnm 3) ;; char needed for last digits to get drawing num -- 3 usually
; ;; 4 when you have an A, B or C in name
;
; ;(print "homedir is ")(print homedir)
; ;(print "ttfil is ")(print ttfil)
; ;(print "f is ") (print f)
; ;(command "style" "standard" "ford_ba" "" "" "" "" "" "") ;make sure that standard is set to Ford font
;
; (setq desclgth (strlen DWGNME))
; ;(PRINC DESCLGTH)
; (setq dwglen (- desclgth 4)) ; length without .dwg -- 4 digits
; (setq startpnt (- dwglen 2)) ; puts you at the start of the number part of drawing name
; (setq DWGNM (substr DWGNME startpnt 3)) ;sheet number digits are usually 3
;
; ; (setq len_unit 😎 ; puts you at the start of the number part of drawing name
; (setq len_unit 😎 ; puts you at the start of the number part of drawing name
; (setq unit_stpnt (- dwglen (- len_unit 1 ))) ; puts you at the start of the number part of drawing name
;
; ;(print "abefore first cond dwgnm is ")(print dwgnm)
; ;; ADDED THIS SECTION BECAUSE WE HAVE DRAWINGS WITH A,B,C - PER MIKE
;
; (cond
; ((= "A" (strcase (substr DWGNM 3 1)))(print (substr DWGNM 3 1))
; (setq len_dwgnm 4)(setq startpnt (- startpnt 1)))
; ((= "B" (strcase (substr DWGNM 3 1)))(print (substr DWGNM 3 1))
; (setq len_dwgnm 4)(setq startpnt (- startpnt 1)))
; ((= "C" (strcase (substr DWGNM 3 1)))(print (substr DWGNM 3 1))
; (setq len_dwgnm 4)(setq startpnt (- startpnt 1)))
; ((= "D" (strcase (substr DWGNM 3 1)))(print (substr DWGNM 3 1))
; (setq len_dwgnm 4)(setq startpnt (- startpnt 1)))
;
;
;
; );END COND
;; 12/2009 -- changed file name from the file name to just the last 8 digits with the .dwg extension
; (setq UNITNM (strcase (substr DWGNME unit_stpnt len_unit))) ;sheet number digits are usually 3
;
; (setq DWGNM (strcase (substr DWGNME startpnt len_dwgnm))) ;sheet number digits are usually 3
; (print "before strip dwgnm") (print DWGNM)
;
; ;;strip out leading zeros for entry into the sheet attribute
; (cond
; ((= "00" (substr DWGNM 1 2)) (setq DWGNM (substr DWGNM 3 (- len_dwgnm 2))))
; ((= "0" (substr DWGNM 1 1)) (setq DWGNM (substr DWGNM 2 (- len_dwgnm 1))))
;
; );end cond
;(setq DWGNM (strcat UNIT DWGNM)) ;add the 1A5 for electrical
(print "dwgnm after cat is ")(print dwgnm)

;call the tags that we choose to keep the
;same in all drawings that we wrote out to
;ttlblk.txt in Ford_TB_OUT
(print "before call to TAGFIND")
(setq newv (read-line f))
(print "first newv is")(print newv)
(TAGFIND "TITLE_LINE1" newv)
(setq newv (read-line f))
(print "2nd newv is")(print newv)
(TAGFIND "TITLE_LINE2" newv)
(setq newv (read-line f))
(TAGFIND "TITLE_LINE3" newv)
(setq newv (read-line f))
(TAGFIND "TITLE_LINE4" newv)
(setq newv (read-line f))
(TAGFIND "DESIGN_SOURCE" newv)
(setq newv (read-line f))
;(print "first newv before ttl_sht is")(print newv)
(TAGFIND "TTL_SHT" newv)
(setq newv (read-line f))
;(print "first newv before DES_BY is")(print newv)

(TAGFIND "DES_BY" newv)
(setq newv (read-line f))
(TAGFIND "DET_BY" newv)
(setq newv (read-line f))
(TAGFIND "DATE_TB" newv) ;GAVE A NEW TAG NAME -- MIGHT CONFLICT WITH SYSTEM NAME
;(TAGFIND "DATE" newv) ;GAVE A NEW TAG NAME -- MIGHT CONFLICT WITH SYSTEM NAME
(setq newv (read-line f))
(TAGFIND "PROGRAM_NAME" newv)
(setq newv (read-line f))
(TAGFIND "CHK_BY" newv)
(setq newv (read-line f))
(TAGFIND "ZF_NO_1" newv)
(setq newv (read-line f))
;;added variables 12/2009 for NextGen Titleblock
(print "before reading new variables and newv is ")(print newv)
(TAGFIND "BUILD_SOURCE" newv)
(setq newv (read-line f))
(TAGFIND "SAFETY" newv)
(setq newv (read-line f))
;(TAGFIND "DIV_NAME" newv)
;(setq newv (read-line f))
;(TAGFIND "PLANT_NAME" newv)
;(setq newv (read-line f))
;(TAGFIND "LOC_ACT" newv)
;(setq newv (read-line f))
(TAGFIND "BUILD_STATUS" newv)
(setq newv (read-line f))
(TAGFIND "SHOP_ORDER_RIGHT" newv)
(print "before last read ")
(setq newv (read-line f))
(print "after last Read newv is ")(print newv)
(TAGFIND "SHOP_ORDER_LEFT" newv)
(print "after last read newv is ")(print newv)

 

 

;;these 2 tags are taken from system variables
;(setq dwgnme (strcat homedir dwgnme))
(TAGFIND "FILE_NAME" dwgnme);dwgname
;(TAGFIND "FILE_NAME" UNITNM);dwgname

(TAGFIND "SHT_NO_1" dwgnm) ;;last 3 digits with leading zeros removed
(TAGFIND "DWGSECTION1" unit) ;;last 3 digits with leading zeros removed

;(print "at end of TAGFIND")
(close f)


) ; end dname

 


;;
;; Globally Modifies Tag Values, All Blocks
;;===========================================================
(defun TAGFIND (tagname newv / tagname ss1 len count bn en el found attstr)
;=================create selection set=======================

(setq ss1 (ssget "x" '((0 . "insert") (66 . 1)))
len (sslength ss1)
count 0
)
(repeat len
(setq bn (ssname ss1 count) ;Block Name
en (entnext bn) ;Entity Name
el (entget en)) ;Entity List


;=================loop thru block entities===================

(while (and (= "ATTRIB" (dxf 0 el))
(/= "SEQEND" (dxf 0 el)))
;(print "(dxf 2 el) before if is ")(print (dxf 2 el))
(if (= (dxf 2 el) (strcase tagname))
(progn

;print "(dxf 2 el) is ")(print (dxf 2 el))
(setq attstr (dxf 1 el))
;print "(dxf 1 el) is ")(print (dxf 1 el))
;(print "attstr is ")(print attstr)
(setq el (subst (cons 1 newv) (assoc 1 el) el))

(entmod el) ;Modify List
(entupd bn) ;Update Screen
(setq found "yes") ;Found Tag?
);progn
) ;if
(setq en (entnext en)
el (entget en))
);while
(setq count (1+ count))
;(print "before repeat")
) ;repeat
(if (/= found "yes")
(princ "\nTag Not Found.")
)

;(princ "at end of TAGFIND")
);defun TAGFINDt.lsp

 

 

 

;======================dxf function==========================
(defun dxf (code elist)
(cdr (assoc code elist))
);dxf
(princ)
;============================================================
QSAVE

 

and here is the code for acad.lsp:

 

;Revised 03/21/2023
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun s::startup ()
(load "InsertBlocks.lsp")
(load "revcloud.lsp")
(load "ac_bonus.lsp")
(print "after revcloud")
(load "BUB-NOTE.lsp")
(load "chspace.lsp")
(load "julian.lsp")
(load "METALSA_TB_OUT.lsp")
(print "after met tb out")
(load "Challenge_TB_In.lsp")
(print "after challenge tb in")
(load "Challenge_TB_Out.lsp")
(print "after challenge tb out")
(load "FD_NG_TB_IN.lsp")
(print "after ngftbin")
(load "FD_NG_TB_OUT.lsp")
(print "after ngftbout")
(load "METALSA_TB_IN.lsp")
(print "after metalsa tb in")
(load "LEN_LINE_FOR_CABLE.lsp")
(load "pl2.lsp")
(load "shortcut.lsp")
(load "anyplot.lsp")
;(load "maketags.lsp")
;(load "gmaketags.lsp")
(load "L:\\9-ControlsDesign\\TAGS\\LISP\\MAKETAGS.LSP" "MakeTagsLisp Failed to Load")
(load "L:\\9-ControlsDesign\\TAGS\\LISP\\GMAKETAGS.LSP" "GMakeTagsLisp Failed to Load")
;(defun c:MAKETAGS() ;DEFINITION OF COMMAND TO BE ENTERED, IN THIS CASE "MAKETAGS"
; (vl-vbarun "L:/9-ControlsDesign/TAGS/VB/StartTags.dvb!Module1.StartTags") ;CALLS THE .dvb FILE TO RUN FROM THE 'SUPPORT' FOLDER
; ;"Support" IS THE FOLDER
; ;"StartTags.dvb" IS THE ACTUAL VBA FILE
; ;"Module1" IS WHERE THE START SCRIPT IS LOCATED
; ;"StartTags" IS THE NAME OF THE FIRST SUB TO BE CALLED
; (princ))
(print "made it to the end")
)

 

Thanks,

 

RH

 

 

0 Likes
Message 4 of 11

ronjonp
Advisor
Advisor

So all those other routines load fine? 

 

This is a bit odd:

ronjonp_0-1680813197321.png

BTW .. here is where the code tags are located. It makes the post more legible.

ronjonp_1-1680813252569.png

 

0 Likes
Message 5 of 11

raceharder
Enthusiast
Enthusiast

Yes.  All the others appear to load fine and work properly. 

 

As far as the section you have pointed out as odd.....I'm not sure what that section does.  This is a lisp that was created by someone prior to me.  I am new to code for lisps and am stumbling my way through...........

 

0 Likes
Message 6 of 11

raceharder
Enthusiast
Enthusiast

I do understand the purpose of the qsave.  I'm just not sure why the dxf function section is there.  I don't find the qsave odd as we want to save the file after updating the titleblock.  Is there a better way to do that or I guess can you clarify why you find that odd?  Not that I am questioning you, I am just trying to learn and understand.  I do appreciate your help.

 

RH

0 Likes
Message 7 of 11

Sea-Haven
Mentor
Mentor

I have always used the Start Up Suite of Appload rather than Acad.lsp etc.

 

2nd comment you have lots of (load "lisp") I would look into the use of AUTOLOAD rather than LOAD it loads the lisp when you type the associated command with that lisp.

 

 

 

(autoload "COPY0" '("COPY0"))
(autoload "COPYCOMMAND" '("CPCOM"))
(autoload "COVER" '("COVER"))

 

 

They are not wrapped in the Startup defun.

0 Likes
Message 8 of 11

raceharder
Enthusiast
Enthusiast

I have added the lisp in question to the startup suite and I got the same results.  It doesn't work unless I appload it.  I will give the other suggestion a shot and see if that works.  Thank you.

0 Likes
Message 9 of 11

raceharder
Enthusiast
Enthusiast

Actually, even when the lisp does run, it updates all the information on the titleblock but I noticed that it never hits the qsave.  I get an "exited:  bad dxf group(1)"  

But it is updating all the information on the titleblock.

 

0 Likes
Message 10 of 11

ronjonp
Advisor
Advisor

TBH if you give a clear description and sample drawing of this attribute updater, I could rewrite the code with a bit more error checking. What you have now is a bit of a mess.

0 Likes
Message 11 of 11

Kent1Cooper
Consultant
Consultant

@raceharder wrote:

I do understand the purpose of the qsave.  ....


But not, apparently, the proper usage of it in an AutoLisp routine.  What's "odd" about it is the use of the raw command name, which would be appropriate in a SCRIPT or a command macro.  In an AutoLisp routine, it should be:

 

(command "_.qsave")

Kent Cooper, AIA
0 Likes