Jump to content

Cách lấy số liệu từ file txt

Chào các anh,em có một đoạn lisp thế này :

(defun DCL ( lstType / fl ret dcl_id Return# add_lst )
(defun add_lst (key lst method)
(start_list key method)
(mapcar 'add_list lst)
(end_list)
)
(vl-load-com)
(setq fl (vl-filename-mktemp "mip" nil ".dcl"))
(setq ret (open fl "w"))
(mapcar
'(lambda (x) (write-line x ret))
(list
" mip_msg : dialog { label = \"ANSI B16.5 FORGED FLANGES\";"
" : boxed_column { label = \"Select The Type Of Flanges\";"
" : list_box { key = \"mylist\";width = 20;}"
" } "
" : boxed_column { label = \"Select Nominal Pipe Size\";"
" : popup_list {key = \"NPS\"; width = 17; height = 8;} "
" } "
" : boxed_column { label = \"Select Wall Thickness\";"
" : edit_box {label = \"Wall Thichkness : t =\"; key = \"Tlon\"; edit_width = 8;}"
" } "
" : row { "
" : button {label = \"OK\"; key = \"accept\"; width = 10; fixed_width = true;} "
" : button {label = \"Cancel\"; is_cancel = true; key = \"cancel\"; width = 10; fixed_width = true;}"
" } "
"} "
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun Get_lwn1()
(setq Tlon (atof (get_tile "Tlon"))
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq ret (close ret))
(if (and (not (minusp (setq dcl_id (load_dialog fl))))
(new_dialog "mip_msg" dcl_id)
)
(progn
(add_lst "mylist" '("CLASS 150 FLANGES UNDER 8 INCH" "CLASS 300 FLANGES UNDER 8 INCH" "CLASS 400 FLANGES UNDER 8 INCH" "CLASS 600 FLANGES UNDER 8 INCH" "CLASS 900 FLANGES UNDER 8 INCH" "CLASS 1500 FLANGES UNDER 8 INCH" "CLASS 150 FLANGES 10-24 INCH" "CLASS 300 FLANGES 10-24 INCH" "CLASS 400 FLANGES 10-24 INCH" "CLASS 600 FLANGES 10-24 INCH" "CLASS 900 FLANGES 10-24 INCH" "CLASS 1500 FLANGES 10-24 INCH") 3)
(set_tile "mylist" "0")
(add_lst "NPS" (mapcar '(lambda (x)(vl-princ-to-string (car x))) (cadadr lst)) 3)
(action_tile "mylist"
"(add_lst \"NPS\" (mapcar '(lambda (x)(vl-princ-to-string (car x))) (cadr (assoc $value lst))) 3)"
)
(action_tile "accept"
"(setq ret (cons (get_tile \"mylist\")
(cadr
(nth (atoi (get_tile \"NPS\")) (cadr (assoc (get_tile \"mylist\") lst))))
)
)(Get_lwn1)(done_dialog)")
(start_dialog)
)
)
(unload_dialog dcl_id)
(vl-file-delete fl)
ret
)
(defun c:wn (/ PR RL lst0 lst1 lst2 lst3 lst4 lst5 lst40 lst41 lst42 lst43 lst44 lst45 val pt lst)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(or fn0
(setq fn0 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 150.txt"))
(setq fn0 (getfiled "Data Welding Neck Under 8 inch class 150" "" "txt" 2)))
(or fn1
(setq fn1 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 300.txt"))
(setq fn1 (getfiled "Data Welding Neck Under 8 inch class 300" "" "txt" 2)))
(or fn2
(setq fn2 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 400.txt"))
(setq fn2 (getfiled "Data Welding Neck Under 8 inch class 400" "" "txt" 2)))
(or fn3
(setq fn3 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 600.txt"))
(setq fn3 (getfiled "Data Welding Neck Under 8 inch class 600" "" "txt" 2)))
(or fn4
(setq fn4 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 900.txt"))
(setq fn4 (getfiled "Data Welding Neck Under 8 inch class 900" "" "txt" 2)))
(or fn5
(setq fn5 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 1500.txt"))
(setq fn5 (getfiled "Data Welding Neck Under 8 inch class 1500" "" "txt" 2)))
(or fn40
(setq fn40 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 150.txt"))
(setq fn40 (getfiled "Data Welding Neck Under 8 inch class 150" "" "txt" 2)))
(or fn41
(setq fn41 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 300.txt"))
(setq fn41 (getfiled "Data Welding Neck Under 8 inch class 300" "" "txt" 2)))
(or fn42
(setq fn42 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 400.txt"))
(setq fn42 (getfiled "Data Welding Neck Under 8 inch class 400" "" "txt" 2)))
(or fn43
(setq fn43 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 600.txt"))
(setq fn43 (getfiled "Data Welding Neck Under 8 inch class 600" "" "txt" 2)))
(or fn44
(setq fn44 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 900.txt"))
(setq fn44 (getfiled "Data Welding Neck Under 8 inch class 900" "" "txt" 2)))
(or fn45
(setq fn45 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 1500.txt"))
(setq fn45 (getfiled "Data Welding Neck Under 8 inch class 1500" "" "txt" 2)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (and fn0 fn1 fn2 fn3 fn4 fn5 fn40 fn41 fn42 fn43 fn44 fn45)
(progn
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn0 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst0 (append lst0 (list (list (car RL)(cdr RL))))
)
)
(setq lst0 (list "0" lst0))
(close PR)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn1 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst1 (append lst1 (list (list (car RL)(cdr RL))))
)
)
(setq lst1 (list "1" lst1))
(close PR)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn2 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst2 (append lst2 (list (list (car RL)(cdr RL))))
)
)
(setq lst2 (list "2" lst2))
(close PR)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn3 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst3 (append lst3 (list (list (car RL)(cdr RL))))
)
)
(setq lst3 (list "3" lst3))
(close PR)
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn4 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst4 (append lst4 (list (list (car RL)(cdr RL))))
)
)
(setq lst4 (list "4" lst4))
(close PR)
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn5 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst5 (append lst5 (list (list (car RL)(cdr RL))))
)
)
(setq lst5 (list "5" lst5))
(close PR)
(setq PR (open fn40 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst40 (append lst40 (list (list (car RL)(cdr RL))))
)
)
(setq lst40 (list "6" lst40))
(close PR)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn41 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst41 (append lst41 (list (list (car RL)(cdr RL))))
)
)
(setq lst41 (list "7" lst41))
(close PR)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn42 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst42 (append lst42 (list (list (car RL)(cdr RL))))
)
)
(setq lst42 (list "8" lst42))
(close PR)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn43 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst43 (append lst43 (list (list (car RL)(cdr RL))))
)
)
(setq lst43 (list "9" lst43))
(close PR)
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn44 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst44 (append lst44 (list (list (car RL)(cdr RL))))
)
)
(setq lst44 (list "10" lst44))
(close PR)
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn45 "r") RL (read-line PR))
(while (setq RL (read-line PR))
(setq RL (read (strcat "(" RL ")"))
lst45 (append lst45 (list (list (car RL)(cdr RL))))
)
)
(setq lst45 (list "11" lst45))
(close PR)
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq lst (list lst0 lst1 lst2 lst3 lst4 lst5 lst40 lst41 lst42 lst43 lst44 lst45))
(if
(and (setq val (DCL lst))
(setq pt (getpoint "\nStart Point:"))
)
(apply 'wna (append val (list pt)))
(princ "Error")
)
)
(princ "\nMissing File")
)
(princ)
)
;--------------------------------------------------------------------------------
(defun wna (Loai D X G tnho T1 A C D1 p1 / OldOS)
(setq OldOs(getvar "osmode"))
(setvar "osmode" 0)
(setq
P2(polar P1 0.0 (/ G 2))
P3(polar P2 (/ pi 2) 1.6)
P4(polar P3 0.0 (/ (- D G) 2))
P5(polar P4 (/ pi 2) tnho)
P6(polar P5 pi (/ (- D X) 2))
P7(polar P1 (/ pi 2) (+ T1 1.6))
P8(polar P7 0.0 (/ A 2))
P9(polar P8 (* pi 1.5) 6)
P10(polar P8 pi Tlon)
P11(polar P10 (* pi 1.5) (+ T1 1.6))
P12(polar P3 0.0 (/ (- C G) 2))
P13(polar P12 pi (/ D1 2))
P14(polar P13 (/ pi 2) tnho)
P15(polar P12 0.0 (/ D1 2))
P16(polar P15 (/ pi 2) tnho)
P17(polar P1 (* pi 1.5) (/ T1 8))
P18(polar P7 (/ pi 2) (/ T1 8))
P19(polar P12 (* pi 1.5) (/ tnho 8))
P20(polar P12 (/ pi 2) (+ tnho (/ tnho 8)))
P21(polar P1 0.0 (/ D 2))
P22(polar P7 pi (/ D 2))
)
(COMMAND "LAYER" "M" "3" "C" "3" "" "L" "CONTINUOUS" "" "")
(command "line" P1 P2 P3 P4 P5 P6 P9 P8 P7 "")
(command "line" P10 P11 "")
(command "line" P13 P14 "")
(command "line" P15 P16 "")
(COMMAND "LAYER" "M" "1" "C" "1" "" "L" "CENTER2" "" "")
(command "line" P17 P18 "")
(command "line" P19 P20 "")
(COMMAND "LAYER" "M" "3" "C" "3" "" "L" "CONTINUOUS" "" "")
(command "zoom" "a" "")
(command "zoom" "w" P21 P22)
(COMMAND "MIRROR" "BOX" P21 P7 "" P1 P7 "" )
(setvar "osmode" OldOs)
(princ)
)


Nếu viết như thế này thì em thấy cách lấy file dữ liệu có vẻ dài quá,có cách nào để làm ngắn gọn lại không vậy các anh ??

Thanks !!!!



Vâng,đúng là đoạn Lisp này em có nhờ anh viết.
Nhưng cái đoạn anh nói ở trên em vẫn ko hiểu rõ lắm cách viết lại thành 1 hàm con đó. :wacko: :wacko:

Cách dùng

  1. Tải tệp 197897_wn.lsp về máy.
  2. Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
  3. Gõ lệnh WN để chạy lisp.

Mã nguồn 197897_wn.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/59801-help-me-c%C3%A1ch-l%E1%BA%A5y-s%E1%BB%91-li%E1%BB%87u-t%E1%BB%AB-file-txt/?page=2&tab=comments#comment-185467
(defun DCL ( lstType / fl ret dcl_id Return# add_lst )
(defun add_lst (key lst method)
(start_list key method)
(mapcar 'add_list lst)
(end_list)
)
 (vl-load-com)
 (setq fl (vl-filename-mktemp "mip" nil ".dcl"))
 (setq  ret (open fl "w"))
 (mapcar
'(lambda (x) (write-line x ret))
(list
 " mip_msg : dialog { label = \"ANSI B16.5 FORGED FLANGES\";"
 " : boxed_column { label = \"Select The Type Of Flanges\";"
 " : list_box { key = \"mylist\";width = 20;}"
 " } "
 " : boxed_column { label = \"Select Nominal Pipe Size\";"
 " : popup_list {key = \"NPS\"; width = 17; height = 8;} "
 " } "
 " : boxed_column { label = \"Select Wall Thickness\";"
 " : edit_box {label = \"Wall Thichkness : t =\"; key = \"Tlon\"; edit_width = 8;}"
 " } "
 " : row { "
 " : button {label = \"OK\"; key = \"accept\"; width = 10; fixed_width = true;} "
 " : button {label = \"Cancel\"; is_cancel = true; key = \"cancel\"; width = 10; fixed_width = true;}"
 " } "
 "} "
)
 )
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (Defun Get_lwn1()
 (setq Tlon (atof (get_tile "Tlon"))
)
)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (setq ret (close ret))
 (if (and (not (minusp (setq dcl_id (load_dialog fl))))
 (new_dialog "mip_msg" dcl_id)
  )
(progn
 (add_lst "mylist" '("CLASS 150 FLANGES UNDER 8 INCH" "CLASS 300 FLANGES UNDER 8 INCH" "CLASS 400 FLANGES UNDER 8 INCH" "CLASS 600 FLANGES UNDER 8 INCH" "CLASS 900 FLANGES UNDER 8 INCH" "CLASS 1500 FLANGES UNDER 8 INCH" "CLASS 150 FLANGES 10-24 INCH" "CLASS 300 FLANGES 10-24 INCH" "CLASS 400 FLANGES 10-24 INCH" "CLASS 600 FLANGES 10-24 INCH" "CLASS 900 FLANGES 10-24 INCH" "CLASS 1500 FLANGES 10-24 INCH") 3)
 (set_tile "mylist" "0")
 (add_lst "NPS" (mapcar '(lambda (x)(vl-princ-to-string (car x))) (cadadr lst)) 3)
 (action_tile "mylist"
  "(add_lst \"NPS\" (mapcar '(lambda (x)(vl-princ-to-string (car x))) (cadr (assoc $value lst))) 3)"
 )
 (action_tile "accept"
 "(setq ret  (cons (get_tile \"mylist\")
  (cadr
  (nth (atoi (get_tile \"NPS\")) (cadr (assoc (get_tile \"mylist\") lst))))
  )
  )(Get_lwn1)(done_dialog)")
 (start_dialog)
)
 )
 (unload_dialog dcl_id)
 (vl-file-delete fl)
ret
)
(defun c:wn (/  PR RL  lst0 lst1 lst2 lst3 lst4 lst5 lst40 lst41 lst42 lst43 lst44 lst45 val pt lst)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(or  fn0
 (setq fn0 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 150.txt"))
 (setq fn0 (getfiled "Data Welding Neck Under 8 inch class 150" "" "txt" 2)))
(or  fn1
 (setq fn1 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 300.txt"))
 (setq fn1 (getfiled "Data Welding Neck Under 8 inch class 300" "" "txt" 2)))
(or  fn2
 (setq fn2 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 400.txt"))
 (setq fn2 (getfiled "Data Welding Neck Under 8 inch class 400" "" "txt" 2)))
(or  fn3
 (setq fn3 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 600.txt"))
 (setq fn3 (getfiled "Data Welding Neck Under 8 inch class 600" "" "txt" 2)))
(or  fn4
 (setq fn4 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 900.txt"))
 (setq fn4 (getfiled "Data Welding Neck Under 8 inch class 900" "" "txt" 2)))
(or  fn5
 (setq fn5 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck Under 8 inch class 1500.txt"))
 (setq fn5  (getfiled "Data Welding Neck Under 8 inch class 1500" "" "txt" 2)))
(or  fn40
 (setq fn40 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 150.txt"))
 (setq fn40 (getfiled "Data Welding Neck Under 8 inch class 150" "" "txt" 2)))
(or  fn41
 (setq fn41 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 300.txt"))
 (setq fn41 (getfiled "Data Welding Neck Under 8 inch class 300" "" "txt" 2)))
(or  fn42
 (setq fn42 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 400.txt"))
 (setq fn42 (getfiled "Data Welding Neck Under 8 inch class 400" "" "txt" 2)))
(or  fn43
 (setq fn43 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 600.txt"))
 (setq fn43 (getfiled "Data Welding Neck Under 8 inch class 600" "" "txt" 2)))
(or  fn44
 (setq fn44 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 900.txt"))
 (setq fn44 (getfiled "Data Welding Neck Under 8 inch class 900" "" "txt" 2)))
(or  fn45
 (setq fn45 (findfile "C:\\Program Files\\Autodesk\\ACADM 2010\\flanges\\Data\\Welding Neck 10-24 inch class 1500.txt"))
 (setq fn45  (getfiled "Data Welding Neck Under 8 inch class 1500" "" "txt" 2)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (and fn0 fn1 fn2 fn3 fn4 fn5 fn40 fn41 fn42 fn43 fn44 fn45)
 (progn
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq PR (open fn0 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst0 (append lst0 (list (list (car RL)(cdr RL))))
  )
)
(setq lst0 (list "0" lst0))
(close PR)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq PR (open fn1 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst1 (append lst1 (list (list (car RL)(cdr RL))))
  )
)
(setq lst1 (list "1" lst1))
(close PR)
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn2 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst2 (append lst2 (list (list (car RL)(cdr RL))))
  )
)
(setq lst2 (list "2" lst2))
(close PR)
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq PR (open fn3 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst3 (append lst3 (list (list (car RL)(cdr RL))))
  )
)
(setq lst3 (list "3" lst3))
(close PR)
  ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq PR (open fn4 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst4 (append lst4 (list (list (car RL)(cdr RL))))
  )
)
(setq lst4 (list "4" lst4))
(close PR)
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq PR (open fn5 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst5 (append lst5 (list (list (car RL)(cdr RL))))
  )
)
(setq lst5 (list "5" lst5))
(close PR)
(setq PR (open fn40 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst40 (append lst40 (list (list (car RL)(cdr RL))))
  )
)
(setq lst40 (list "6" lst40))
(close PR)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq PR (open fn41 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst41 (append lst41 (list (list (car RL)(cdr RL))))
  )
)
(setq lst41 (list "7" lst41))
(close PR)
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq PR (open fn42 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst42 (append lst42 (list (list (car RL)(cdr RL))))
  )
)
(setq lst42 (list "8" lst42))
(close PR)
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq PR (open fn43 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst43 (append lst43 (list (list (car RL)(cdr RL))))
  )
)
(setq lst43 (list "9" lst43))
(close PR)
  ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq PR (open fn44 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst44 (append lst44 (list (list (car RL)(cdr RL))))
  )
)
(setq lst44 (list "10" lst44))
(close PR)
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq PR (open fn45 "r") RL (read-line PR))
  (while  (setq RL (read-line PR))
  (setq   RL (read (strcat "(" RL ")"))
  lst45 (append lst45 (list (list (car RL)(cdr RL))))
  )
)
(setq lst45 (list "11" lst45))
(close PR)
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq lst (list lst0 lst1 lst2 lst3 lst4 lst5 lst40 lst41 lst42 lst43 lst44 lst45))
(if
(and (setq val (DCL lst))
  (setq pt (getpoint "\nStart Point:"))
)
(apply 'wna (append val (list pt)))
(princ "Error")
)
)
(princ "\nMissing File")
)
(princ)
)
;--------------------------------------------------------------------------------
(defun wna (Loai D X G tnho T1 A C D1 p1 / OldOS)
 (setq OldOs(getvar "osmode"))
  (setvar "osmode" 0)
(setq
P2(polar P1 0.0 (/ G 2))
P3(polar P2 (/ pi 2) 1.6)
P4(polar P3 0.0 (/ (- D G) 2))
P5(polar P4 (/ pi 2) tnho)
P6(polar P5 pi (/ (- D X) 2))
P7(polar P1 (/ pi 2) (+ T1 1.6))
P8(polar P7 0.0 (/ A 2))
P9(polar P8 (* pi 1.5) 6)
P10(polar P8 pi Tlon)
P11(polar P10 (* pi 1.5) (+ T1 1.6))
P12(polar P3 0.0 (/ (- C G) 2))
P13(polar P12 pi (/ D1 2))
P14(polar P13 (/ pi 2) tnho)
P15(polar P12 0.0 (/ D1 2))
P16(polar P15 (/ pi 2) tnho)
P17(polar P1 (* pi 1.5) (/ T1 8))
P18(polar P7 (/ pi 2) (/ T1 8))
P19(polar P12 (* pi 1.5) (/ tnho 8))
P20(polar P12 (/ pi 2) (+ tnho (/ tnho 8)))
P21(polar P1 0.0 (/ D 2))
P22(polar P7 pi (/ D 2))
)
 (COMMAND "LAYER" "M" "3" "C" "3" "" "L" "CONTINUOUS" "" "")
 (command "line" P1 P2 P3 P4 P5 P6 P9 P8 P7 "")
 (command "line" P10 P11 "")
 (command "line" P13 P14 "")
 (command "line" P15 P16 "")
 (COMMAND "LAYER" "M" "1" "C" "1" "" "L" "CENTER2" "" "")
 (command "line" P17 P18 "")
 (command "line" P19 P20 "")
 (COMMAND "LAYER" "M" "3" "C" "3" "" "L" "CONTINUOUS" "" "")
 (command "zoom" "a" "")
 (command "zoom" "w" P21 P22)
 (COMMAND "MIRROR" "BOX" P21 P7 "" P1 P7 "" )
(setvar "osmode" OldOs)
 (princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Help me] Cách lấy số liệu từ file txt. Xem đúng bài viết #197897 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 88)