Jump to content

Lisp lệnh TTT trong chủ đề “[ Yêu cầu ] Nhờ chỉnh lisp xác định lý trình - cách tim”

;; Write CSV - Lee Mac
;; Writes a matrix list of cell values to a CSV file.
;; lst - list of lists, sublist is row of cell values
;; csv - filename of CSV file to write
;; Returns T if successful, else nil

(defun LM:writecsv ( lst csv / des sep )
(if (setq des (open csv "w"))
(progn
(setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))
(foreach row lst (write-line (LM:lst->csv row sep) des))
(close des)
t
)
)
)

;; List -> CSV - Lee Mac
;; Concatenates a row of cell values to be written to a CSV file.
;; lst - list containing row of CSV cell values
;; sep - CSV separator token

(defun LM:lst->csv ( lst sep )
(if (cdr lst)
(strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep))
(LM:csv-addquotes (car lst) sep)
)
)

(defun LM:csv-addquotes ( str sep / pos )
(cond
( (wcmatch str (strcat "**"))
(setq pos 0)
(while (setq pos (vl-string-position 34 str pos))
(setq str (vl-string-subst "\"\"" "\"" str pos)
pos (+ pos 2)
)
)
(strcat "\"" str "\"")
)
( str )
)
)
(defun C:ttt(/ e obj pt pt1 dis lt lst)
(vl-load-com)
(setq e (car (entsel "Chon PL")))
(setq obj (vlax-ename->vla-object e))
(setq lst (list (list "Lytrinh" "Cach tim" "Toa do X" "Toa do Y")))
(while (setq pt (getpoint "\nPick diem"))
(setq pt1 (vlax-curve-getClosestPointTo obj pt))
(setq dis (distance pt pt1))
(setq lt (vlax-curve-getDistAtPoint obj pt1))
(princ (strcat "Ly trinh = " (rtos lt 2 2) "\nKhoach cach den tim = " (rtos dis 2 2)))
(setq lst (cons (list (rtos lt 2 2) (rtos dis 2 2) (rtos (car pt1) 2 3) (rtos (cadr pt1) 2 3)) lst))
)
(if (and
(setq fn (getfiled "Create Output File" "" "csv" 1))
(LM:WriteCSV (reverse lst) fn)
)
(startapp "explorer" fn)
)

)

 

 

Trong lúc chờ đợi bác Phamthanhbinh có 1 lisp chuẩn hơn. Tôi làm sơ bộ cho bạn như thế này. Có thể chữa cháy trước mắt cho yêu cầu của bạn. Hì hì

Cách dùng

  1. Tải tệp 286793_ttt.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 TTT để chạy lisp.

Mã nguồn 286793_ttt.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/98205-y%C3%AAu-c%E1%BA%A7u-nh%E1%BB%9D-ch%E1%BB%89nh-lisp-x%C3%A1c-%C4%91%E1%BB%8Bnh-l%C3%BD-tr%C3%ACnh-c%C3%A1ch-tim/
;; Write CSV - Lee Mac;; Writes a matrix list of cell values to a CSV file.;; lst - [lst] list of lists, sublist is row of cell values;; csv - [str] filename of CSV file to write;; Returns T if successful, else nil(defun LM:writecsv ( lst csv / des sep )(if (setq des (open csv "w"))(progn(setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))(foreach row lst (write-line (LM:lst->csv row sep) des))(close des)t)));; List -> CSV - Lee Mac;; Concatenates a row of cell values to be written to a CSV file.;; lst - [lst] list containing row of CSV cell values;; sep - [str] CSV separator token(defun LM:lst->csv ( lst sep )(if (cdr lst)(strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep))(LM:csv-addquotes (car lst) sep)))(defun LM:csv-addquotes ( str sep / pos )(cond( (wcmatch str (strcat "*[`" sep "\"]*"))(setq pos 0)(while (setq pos (vl-string-position 34 str pos))(setq str (vl-string-subst "\"\"" "\"" str pos)pos (+ pos 2)))(strcat "\"" str "\""))( str )))(defun C:ttt(/ e obj pt pt1 dis lt lst)(vl-load-com)(setq e (car (entsel "Chon PL")))(setq obj (vlax-ename->vla-object e))(setq lst (list (list "Lytrinh" "Cach tim" "Toa do X" "Toa do Y")))(while (setq pt (getpoint "\nPick diem"))(setq pt1 (vlax-curve-getClosestPointTo obj pt))(setq dis (distance pt pt1))(setq lt (vlax-curve-getDistAtPoint obj pt1))(princ (strcat "Ly trinh = " (rtos lt 2 2) "\nKhoach cach den tim = " (rtos dis 2 2)))(setq lst (cons (list (rtos lt 2 2) (rtos dis 2 2) (rtos (car pt1) 2 3) (rtos (cadr pt1) 2 3)) lst)))(if (and(setq fn (getfiled "Create Output File" "" "csv" 1))(LM:WriteCSV (reverse lst) fn))(startapp "explorer" fn)))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [ Yêu cầu ] Nhờ chỉnh lisp xác định lý trình - cách tim. Xem đúng bài viết #286793 để đọc hướng dẫn và trao đổi thêm.

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