I added an if statement at the very beginning of the code to test to see if the value of sFmtPath is either nil or is not a string. If either of those conditions is true, the value is reset to an empty string [""]. If neither is true, the string value is left as is. This string value is then passed as the second argument to the getfiled function. If you check the old code, you will see that this was hard-coded as an empty string, so on first use in a drawing editing session (or if the value was somehow changed to a non-string value), the program will run just the way the old one did, starting in the My Documents folder. But after that first run, supplying the folder path there and setting the flags argument (last argument) to 16 (setting the 4 bit) has the getfiled function use that folder as the initial starting folder, making it easier to check multiple files in the same folder, or a folder that is close by in the folder structure.
I suppose the initial test should, if sFmtPath does contain a string, also then check to see if that string represents a folder on the current machine, but, for now, I decided that would be overkill. Unless you intentionally mess with the value of sFmtPath or if you have another program that also sets a value of a global variable that is also named sFmtPath, there should not be any issues.
Here is the revised AutoLISP code.
(defun C:FMT ( / file1 sfile1 sline1 stext1)
(if (or
(not sFmtPath)
(/= 'STR (type sFmtPath))
) ;_ End or.
(setq sFmtPath "")
) ;_ End if.
(setq sfile1 (getfiled "Select Drawing File" sFmtPath "dwg" 16)
file1 (open sfile1 "r")
) ;_ End setq.
(if file1
(progn
(setq sline1 (read-line file1)
stext1 (substr sline1 1 6)
sFmtPath (vl-filename-directory sfile1)
) ;_ End setq.
(close file1)
(cond ; Condition A.
((= "AC1032" stext1)
(alert
(strcat
"Header = AC1032."
"\nFile " sfile1
"\nis saved in the 2018 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A1.
((= "AC1027" stext1)
(alert
(strcat
"Header = AC1027."
"\nFile " sfile1
"\nis saved in the 2013 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A2.
((= "AC1024" stext1)
(alert
(strcat
"Header = AC1024."
"\nFile " sfile1
"\nis saved in the 2010 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A3.
((= "AC1021" stext1)
(alert
(strcat
"Header = AC1021."
"\nFile " sfile1
"\nis saved in the 2007 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A4.
((= "AC1018" stext1)
(alert
(strcat
"Header = AC1018."
"\nFile " sfile1
"\nis saved in the 2004 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A5.
((= "AC1015" stext1)
(alert
(strcat
"Header = AC1015."
"\nFile " sfile1
"\nis saved in the 2000 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A6.
((= "AC1014" stext1)
(alert
(strcat
"Header = AC1014."
"\nFile " sfile1
"\nis saved in the R14 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A7.
((= "AC1012" stext1)
(alert
(strcat
"Header = AC1012."
"\nFile " sfile1
"\nis saved in the R13 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A8.
((= "AC1009" stext1)
(alert
(strcat
"Header = AC1009."
"\nFile " sfile1
"\nis saved in the R11/R12 file
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A9.
((= "AC1006" stext1)
(alert
(strcat
"Header = AC1006."
"\nFile " sfile1
"\nis saved in the R10 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A10.
((= "AC1004" stext1)
(alert
(strcat
"Header = AC1004."
"\nFile " sfile1
"\nis saved in the R9 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A11.
((= "AC1003" stext1)
(alert
(strcat
"Header = AC1003."
"\nFile " sfile1
"\nis saved in the Version 2.60 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A12.
((= "AC1002" stext1)
(alert
(strcat
"Header = AC1002."
"\nFile " sfile1
"\nis saved in the Version 2.50 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A13.
((= "AC1001" stext1)
(alert
(strcat
"Header = AC1001."
"\nFile " sfile1
"\nis saved in the Version 2.22 file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A14.
(T
(alert
(strcat
"Header = "
stext1
"\nFile " sfile1
"\nis saved in an unknown file format."
) ;_ End strcat.
) ;_ End alert.
) ;_ End condition A15.
) ;_ End condition A.
) ;_ End progn.
(prompt "\nNo file selected. ")
) ;_ End if.
(prin1)
) ;_ End C:FMT
No comments:
Post a Comment