Lisp lệnh XUAT trong chủ đề “Xuất Tọa Độ Và Khoảng Cách Cộng Dồn Pline Ra File Excel”
Bạn dùng thử cái này:
p/s: Bạn nên sửa tiêu đề trước khi bịi mod xóa bài :D
;Xuat X tuong doi va Y tuyet doi cua polyline (defun c:XUAT( / ss lst_name fn pw i ename TT) (vl-load-com) (prompt "\nChon PL !") (setq ss (ssget '((0 . "LWPOLYLINE")))) (cond (ss (setq lst_name (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (setq fn (getfiled "Chon file de xuat ket qua" "" "csv" 1)) (setq pw (open fn "w")) (write-line "STT PL,Ten dinh,Y _tuyet doi,X _tuong doi" pw) (setq i 0) (while (< i (length lst_name)) (setq ename (nth i lst_name) i (1+ i) lst_ver (acet-geom-vertex-list ename) ) (write-line (setq TT (itoa i)) pw) (MakeText (car lst_ver) TT 1 0 "C" nil "Lay_Lsp_XUAT" 2 nil) (foreach pnt lst_ver (write-line (strcat "," (rtos (1+ (vl-position pnt lst_ver))) "," (rtos (cadr pnt) 2 2) "," (rtos (- (car pnt) (car (car lst_ver))) 2 2)) pw) ) ) ) ) (close pw) (alert (strcat "Da them " (itoa (length lst_name)) " Text STT PL vao ban ve !")) (princ) ) ;===================================|; (defun MakeText (point string Height Ang justify Style Layer Color xdata / Lst) ; Ang: Radial (setq Lst (list '(0 . "TEXT") (cons 8 (if Layer Layer (getvar "Clayer"))) (cons 62 (if Color Color 256)) (cons 10 point) (cons 40 Height) (cons 1 string) (if Ang (cons 50 Ang)) (cons 7 (if Style Style (getvar "Textstyle"))) (cons -3 (if xdata (list xdata) nil))) justify (strcase justify)) (cond ((= justify "C") (setq Lst (append Lst (list (cons 72 1) (cons 11 point))))) ((= justify "R") (setq Lst (append Lst (list (cons 72 2) (cons 11 point))))) ((= justify "M") (setq Lst (append Lst (list (cons 72 4) (cons 11 point))))) ((= justify "TL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 3))))) ((= justify "TC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 3))))) ((= justify "TR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 3))))) ((= justify "ML") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 2))))) ((= justify "MC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 2))))) ((= justify "MR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 2))))) ((= justify "BL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 1))))) ((= justify "BC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 1))))) ((= justify "BR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 1))))) ) (entmakex Lst) );end
- Tải lisp
- 385532_xuat.lsp
Cách dùng
- Tải tệp 385532_xuat.lsp về máy.
- 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 XUAT để chạy lisp.
Mã nguồn 385532_xuat.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/154331-xu%E1%BA%A5t-t%E1%BB%8Da-%C4%91%E1%BB%99-v%C3%A0-kho%E1%BA%A3ng-c%C3%A1ch-c%E1%BB%99ng-d%E1%BB%93n-pline-ra-file-excel/
;Xuat X tuong doi va Y tuyet doi cua polyline
(defun c:XUAT( / ss lst_name fn pw i ename TT)
(vl-load-com)
(prompt "\nChon PL !")
(setq ss (ssget '((0 . "LWPOLYLINE"))))
(cond
(ss
(setq lst_name (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
(setq fn (getfiled "Chon file de xuat ket qua" "" "csv" 1))
(setq pw (open fn "w"))
(write-line "STT PL,Ten dinh,Y _tuyet doi,X _tuong doi" pw)
(setq i 0)
(while (< i (length lst_name))
(setq ename (nth i lst_name)
i (1+ i)
lst_ver (acet-geom-vertex-list ename)
)
(write-line (setq TT (itoa i)) pw)
(MakeText (car lst_ver) TT 1 0 "C" nil "Lay_Lsp_XUAT" 2 nil)
(foreach pnt lst_ver
(write-line (strcat "," (rtos (1+ (vl-position pnt lst_ver))) "," (rtos (cadr pnt) 2 2) "," (rtos (- (car pnt) (car (car lst_ver))) 2 2)) pw)
)
)
)
)
(close pw)
(alert (strcat "Da them " (itoa (length lst_name)) " Text STT PL vao ban ve !"))
(princ)
)
;===================================|;
(defun MakeText (point string Height Ang justify Style Layer Color xdata / Lst)
; Ang: Radial
(setq Lst (list '(0 . "TEXT")
(cons 8 (if Layer Layer (getvar "Clayer")))
(cons 62 (if Color Color 256))
(cons 10 point)
(cons 40 Height)
(cons 1 string)
(if Ang (cons 50 Ang))
(cons 7 (if Style Style (getvar "Textstyle")))
(cons -3 (if xdata (list xdata) nil)))
justify (strcase justify))
(cond ((= justify "C") (setq Lst (append Lst (list (cons 72 1) (cons 11 point)))))
((= justify "R") (setq Lst (append Lst (list (cons 72 2) (cons 11 point)))))
((= justify "M") (setq Lst (append Lst (list (cons 72 4) (cons 11 point)))))
((= justify "TL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 3)))))
((= justify "TC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 3)))))
((= justify "TR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 3)))))
((= justify "ML") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 2)))))
((= justify "MC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 2)))))
((= justify "MR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 2)))))
((= justify "BL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 1)))))
((= justify "BC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 1)))))
((= justify "BR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 1)))))
)
(entmakex Lst)
);endThảo luận gốc
Lisp được chia sẻ trong chủ đề Xuất Tọa Độ Và Khoảng Cách Cộng Dồn Pline Ra File Excel. Xem đúng bài viết #385532 để đọc hướng dẫn và trao đổi thêm.