I have a question on how to format the data going into a text file.
the code that I have so far.......
Code:
(defun bo_add_space (a b c)
(if (= c 1) ;;add spaces after string
(repeat (- b (strlen a))
(setq a (strcat a " "))
)
(repeat (- b (strlen a))
(setq a (strcat " " a))
)
)
a
)
;;buyout list created, now format and write to file
(setq bo1 (strcat (getvar "dwgprefix")(getvar "dwgname"))
bo2 (get_date) ;;current system date
bo3 (dos_file bo1) ;;file information
bo4 (get_project_info) ;;project information
bo5 (strcat (getvar "dwgprefix") "BUYOUT" (substr bo2 1 2)(substr bo2 4 2)(substr bo2 7 2) ".txt") ;;output file
)
(dos_delete bo5) ;;if file already exists, delete it
(if (setq f1 (open bo5 "w"))
(progn
(write-line "Buyout Generator Results" f1)
(write-line (strcat "Generated: " bo2) f1)
(write-line (strcat "Drawing File: " bo1) f1)
(write-line (strcat "Buyout File Name: " bo5) f1)
(write-line (strcat (nth 0 bo4) " " (nth 1 bo4)) f1) ;;project name
(write-line (nth 2 bo4) f1) ;;location
(write-line "" f1)
(write-line (strcat "CAD Engineer: " (nth 7 bo4)) f1)
(write-line "" f1)
(write-line sta f1)
(write-line "" f1)
(write-line "QTY Part# Description" f1)
(foreach x a1
(if (= (type (cadr x)) 'INT)
(write-line (strcat (bo_add_space (itoa (cadr x)) 7 1) " " (car x) " " (nth 2 x)) f1)
(write-line (strcat (bo_add_space (rtos (cadr x) 2 1) 7 1) " " (car x) " " (nth 2 x)) f1)
)
)
(write-line "" f1)
(write-line "Cabinets With Assumed Buyouts That Do Not Have Part Numbers Assigned:" f1)
(write-line "" f1)
(write-line "Cabinet: Cabinet Number(s):" f1)
(foreach x no_bo
(write-line (strcat (car x) " " (cadr x)) f1)
)
(write-line "" f1)
(write-line "< END OF REPORT >" f1)
(setq f1 (close f1))
(princ "Done.")
(dos_shellexe "notepad.exe" bo5)
)
(alert "Cannot Open Output File!")
)
The result that I am getting:
STATUS: FINAL
QTY Part# Description
30 2-02027 WHT/2-02035 BLK 12 3/4 MUSIC CABINET SHELF LINER 31 DEEP
30 2-05323 12 1/8W X 15 5/8H WIRE GRILL DR
30 2-05457 MUSIC DOOR NEW WIDE BODY HASP PLATE
Cabinets With Assumed Buyouts That Do Not Have Part Numbers Assigned:
Cabinet: Cabinet Number(s):
< END OF REPORT >
My part numbers vary from 7-23 characters. How do I get each line of the description to line up eventhough the part number length varies?
Thanks for any help you might have!
Ed