Error in Code at (while (findfile) ... Error: bad argument type: stringp nil

Error in Code at (while (findfile) ... Error: bad argument type: stringp nil

hawarch
Participant Participant
270 Views
3 Replies
Message 1 of 4

Error in Code at (while (findfile) ... Error: bad argument type: stringp nil

hawarch
Participant
Participant

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

0 Likes
271 Views
3 Replies
Replies (3)
Message 2 of 4

Sea-Haven
Mentor
Mentor

You may be better getting a list of filenames Visual Lisp - Directories and Files - Page I. (afralisp.net) then use that do a sort etc and look at last.

0 Likes
Message 3 of 4

hawarch
Participant
Participant
Thanks, I'll look into doing it that way as well. Still does not make sense as to why the (while (findfile xx)
method will not work.
0 Likes
Message 4 of 4

paullimapa
Mentor
Mentor

Doesn't seem to error out for me as I step through your lines of code all the way through to your while loop with the drawing file under My Documents.

Have you tried running the code one line at a time to see if that works for you?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes