Lisp chuyển cao độ đo đạc thực tế vào Cad
Hề hề hề,
Bạn xài thử cái của đi mót này xem nhé.
;Lisp by nPham. www.cadviet.com (defun csv->list (fn / str f lst) (defun Separate (str sym / lst pos ) (setq Lst (append)) (while (setq pos (vl-string-search sym str)) (setq Lst (append Lst (list (substr str 1 pos)))) (setq str (substr str (+ pos 2))) ) Lst) (setq f (open fn "r")) (setq lst (append)) (read-line f) (while (setq str (read-line f)) (setq lst (append lst (list (Separate str ","))))) (close f) lst ) (defun text->cad (pt1 cnt tlst / pt1 pt2) ;10 60 20 20 40 (setvar "CECOLOR" "BYLAYER") (command ".text" "J" "MC" (list (+ (car pt1) 5) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 0 tlst)) (command ".text" "J" "ML" (list (+ (car pt1) 12) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 1 tlst)) (command ".text" "J" "MC" (list (+ (car pt1) 80) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 2 tlst)) (command ".text" "J" "MC" (list (+ (car pt1) 100) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 3 tlst)) (command ".text" "J" "MC" (list (+ (car pt1) 130) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 4 tlst)) (setvar "CECOLOR" "8") (command ".line" (setq pt2 (list (car pt1) (- (nth 1 pt1) (* 5 (+ cnt 1))))) (polar pt2 0 150) "") ) (defun c:csv (/ fn f lst wlst i x col pt tile) (setq fn (getfiled "Select Data File" "" "csv" 0)) (if fn (if (setq pt (getpoint "\nDiem chen <Cancel>:")) (progn (setq f (open fn "r")) (setq tile (read-line f)) (close f) (setq lst (vl-remove-if '(lambda (x) (apply 'and (mapcar '(lambda (y) (= y "")) x)))(csv->list fn))) (command ".text" "J" "MC" (list (+ (car pt) 75) (+ (cadr pt) 8)) "4" "0" tile) (setvar "CECOLOR" "7") (command ".line" pt (polar pt 0 150) "") (setq row 0) (mapcar '(lambda (x) (setq row (+ row 1)) (text->cad pt (- row 1) x)) lst ) (setvar "cecolor" "7") (command "line" pt (polar pt (- (/ pi 2)) (* row 5)) "") (command ".copy" (entlast) "" pt (polar pt 0 10)) (command ".copy" (entlast) "" pt (polar pt 0 60)) (command ".copy" (entlast) "" pt (polar pt 0 20)) (command ".copy" (entlast) "" pt (polar pt 0 20)) (command ".copy" (entlast) "" pt (polar pt 0 40)) ))) )Hy vọng bạn hài lòng.
bạn có thể hướng dẫn mình kỹ một chút không? Ví dụ các tọa độ mình đã nhập hết vào excel rồi. Đã load lisp xong rồi. Bước tiếp theo là làm những j?
cảm ơn nhiều vì mình không biết nhiều về lisp!
Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.
Cách dùng
- Chép mã nguồn, lưu thành tệp 154798_csv.lsp.
- 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ẽ.
- Gõ lệnh CSV để chạy lisp.
Mã nguồn 154798_csv.lsp (trích từ bài viết gốc)
;Lisp by nPham. www.cadviet.com
(defun csv->list (fn / str f lst)
(defun Separate (str sym / lst pos )
(setq Lst (append))
(while (setq pos (vl-string-search sym str))
(setq Lst (append Lst (list (substr str 1 pos))))
(setq str (substr str (+ pos 2)))
) Lst)
(setq f (open fn "r"))
(setq lst (append))
(read-line f)
(while (setq str (read-line f)) (setq lst (append lst (list (Separate str ",")))))
(close f)
lst
)
(defun text->cad (pt1 cnt tlst / pt1 pt2)
;10 60 20 20 40
(setvar "CECOLOR" "BYLAYER")
(command ".text" "J" "MC" (list (+ (car pt1) 5) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 0 tlst))
(command ".text" "J" "ML" (list (+ (car pt1) 12) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 1 tlst))
(command ".text" "J" "MC" (list (+ (car pt1) 80) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 2 tlst))
(command ".text" "J" "MC" (list (+ (car pt1) 100) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 3 tlst))
(command ".text" "J" "MC" (list (+ (car pt1) 130) (- (- (cadr pt1) (* 5 cnt)) 2.5)) "2" "0" (nth 4 tlst))
(setvar "CECOLOR" "8")
(command ".line" (setq pt2 (list (car pt1) (- (nth 1 pt1) (* 5 (+ cnt 1))))) (polar pt2 0 150) "")
)
(defun c:csv (/ fn f lst wlst i x col pt tile)
(setq fn (getfiled "Select Data File" "" "csv" 0))
(if fn
(if (setq pt (getpoint "\nDiem chen <Cancel>:"))
(progn
(setq f (open fn "r"))
(setq tile (read-line f))
(close f)
(setq lst (vl-remove-if '(lambda (x) (apply 'and (mapcar '(lambda (y) (= y "")) x)))(csv->list fn)))
(command ".text" "J" "MC" (list (+ (car pt) 75) (+ (cadr pt) 8)) "4" "0" tile)
(setvar "CECOLOR" "7")
(command ".line" pt (polar pt 0 150) "")
(setq row 0)
(mapcar '(lambda (x)
(setq row (+ row 1))
(text->cad pt (- row 1) x))
lst
)
(setvar "cecolor" "7")
(command "line" pt (polar pt (- (/ pi 2)) (* row 5)) "")
(command ".copy" (entlast) "" pt (polar pt 0 10))
(command ".copy" (entlast) "" pt (polar pt 0 60))
(command ".copy" (entlast) "" pt (polar pt 0 20))
(command ".copy" (entlast) "" pt (polar pt 0 20))
(command ".copy" (entlast) "" pt (polar pt 0 40))
)))
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Đã xong] Lisp chuyển cao độ đo đạc thực tế vào Cad. Xem đúng bài viết #154798 để đọc hướng dẫn và trao đổi thêm.