Error in Code at (while (findfile) ... Error: bad argument type: stringp nil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Writing a Lisp program that will create a new sheet in the project file directory. Using a "while" command to see if the sheet exist using "findfile" and if it does, then add the next available sheet number until it finds a sheet that does not exist, then create and open it. I'm getting this error at the "(while (findfile fp) ... " point in the code. Cannot understand why. Can anyone help. THanks.
(defun c:newshtx (/ shtin fnd job fin sht1 sht2 fnx fo fp)
(if (= nil fns)(setq fns "A300.00" ))
(setq hadn (getvar "dwgname")) ;current drawing name
(setq hapa (getvar "dwgprefix"));current path
(princ (strcat "\nSheet will be created into the Current Folder: " hapa " "))
(setq job (substr (getvar "dwgname") 1 7)
fnx 0
fo (strcat job " A000.99.DWG")
fp (strcat hapa job " " fns ".dwg") );s
(princ (strcat "\n " fp))
(if (= (substr fns 5 1) ".")(setq fnp (substr fns 1 2)) (setq fnp (substr fns 1 3)) );i
(while (findfile fp) (setq fp (strcat hapa job " " fnp
(setq fnn (if (<= 10 fnx) (itoa (setq fnx (1+ fnx))) (strcat "0" (itoa (setq fnx (1+ fnx)))) )) ".00.dwg") );s
(setq fn (strcat fnp fnn))
(princ (strcat "\n " fp " | " fn)) );w
(if (numberp (read (substr (getvar "dwgname") 1 4)))(progn
(setq fin (strcase (getstring (strcat "\nPress Return to Accept Next Drawing Number (" fnp "-" (substr fnn 1 5) ") or Assign New Number: "))))
(if (= fin "")(setq fn fn)(setq fn fin))
(if (findfile fp)(alert (strcat "Sheet " fn " Already Exist. \nVerify Next Available Sheet Number and Try Again."))(progn
(if (findfile fo)(progn
(vl-file-copy (findfile fo) fp)
(vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) fp)) );p
(alert (strcat "Master Sheet " fo " Not Found")) );i
))) ;pi p
(alert "File Cannot be Created - Open a Drawing File in the Project's Job Folder and Run Again") );i