Lisp lệnh 00 trong chủ đề “Nhờ viết Lsp xuất toạ độ tâm block”
8 giờ trước, hoangtienphuchung2014 đã nói:Cảm ơn bác Duân và Phạm Yến đã viết và chia sẻ! Mình vừa tải về nhưng lúc chạy thử thì báo lỗi! Thật làm phiền các bạn lần nữa nhé
Bạn ấy gửi thiếu hàm!
(defun C:00 (/ DEM I LTSBL LTSDONG SSBL TDO)
;;;;;;;XUAT TOA DO BLOCK
(vl-load-com)
(setvar "CMDECHO" 0)
(setq ssBl (ssget (list (cons 0 "INSERT"))))
(if ssBl
(progn
(setq LtsBl (acet-ss-to-list ssBl))
(setq LtsDong nil)
(setq i 1)
(foreach eBl LtsBl
(setq Tdo (cdr (assoc 10 (entget eBl))))
(setq LtsDong (append LtsDong
(list (list (rtos i 2 0)
(rtos (cadr Tdo) 2 3)
(rtos (car Tdo) 2 3)
(rtos (caddr Tdo) 2 3)
)
)
)
)
(setq i (1+ i))
)
(setq Dem (length LtsDong))
(alert
(strcat "\nC\U+00F3 t\U+1EA5t c\U+1EA3 "
(rtos Dem 2 0)
" \U+0111\U+01B0\U+1EE3c xu\U+1EA5t t\U+1ECDa \U+0111\U+1ED9"
)
)
(if (/= Dem 0)
(progn
(if (vlax-get-or-create-object "Excel.Application")
(WriteToExcel LtsDong)
(WriteToCSV LtsDong)
)
)
)
)
)
(princ)
)
(defun WriteToExcel (lst_data / col row x xlApp xlCells)
(setq xlApp (vlax-get-or-create-object "Excel.Application")
xlCells (vlax-get-property
(vlax-get-property
(vlax-get-property
(vlax-invoke-method
(vlax-get-property xlApp "Workbooks")
"Add"
)
"Sheets"
)
"Item"
1
)
"Cells"
)
)
(setq row 1)
(foreach pt lst_data
(setq col 1)
(foreach coor pt
(vlax-put-property xlCells 'Item row col coor)
(setq col (1+ col))
)
(setq row (1+ row))
)
(vla-put-visible xlApp :vlax-true)
(mapcar
(function (lambda (x)
(vl-catch-all-apply
(function (lambda ()
(if x
(vlax-release-object x)
)
)
)
)
)
)
(list xlCells xlApp)
)
(gc)
(gc)
)
(defun WriteToCSV (lst_data / fl)
(if (setq fl (getfiled "Output File" "" "csv" 1))
(if (setq fl (open fl "w"))
(progn
(foreach pt lst_data
(write-line
(LM:lst->str pt ",")
fl
)
)
(close fl)
)
)
)
(princ)
)
;|«Visual LISP© Format Options»
(200 2 60 2 nil "end of " 80 9 0 0 0 T T T T)
;*** DO NOT add text below the comment! ***|;
- Tải lisp
- 447327_00.lsp
Cách dùng
- Tải tệp 447327_00.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 00 để chạy lisp.
Mã nguồn 447327_00.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/181681-nh%E1%BB%9D-vi%E1%BA%BFt-lsp-xu%E1%BA%A5t-to%E1%BA%A1-%C4%91%E1%BB%99-t%C3%A2m-block/
(defun C:00 (/ DEM I LTSBL LTSDONG SSBL TDO)
;;;;;;;XUAT TOA DO BLOCK
(vl-load-com)
(setvar "CMDECHO" 0)
(setq ssBl (ssget (list (cons 0 "INSERT"))))
(if ssBl
(progn
(setq LtsBl (acet-ss-to-list ssBl))
(setq LtsDong nil)
(setq i 1)
(foreach eBl LtsBl
(setq Tdo (cdr (assoc 10 (entget eBl))))
(setq LtsDong (append LtsDong
(list (list (rtos i 2 0)
(rtos (cadr Tdo) 2 3)
(rtos (car Tdo) 2 3)
(rtos (caddr Tdo) 2 3)
)
)
)
)
(setq i (1+ i))
)
(setq Dem (length LtsDong))
(alert
(strcat "\nC\U+00F3 t\U+1EA5t c\U+1EA3 "
(rtos Dem 2 0)
" \U+0111\U+01B0\U+1EE3c xu\U+1EA5t t\U+1ECDa \U+0111\U+1ED9"
)
)
(if (/= Dem 0)
(progn
(if (vlax-get-or-create-object "Excel.Application")
(WriteToExcel LtsDong)
(WriteToCSV LtsDong)
)
)
)
)
)
(princ)
)
(defun WriteToExcel (lst_data / col row x xlApp xlCells)
(setq xlApp (vlax-get-or-create-object "Excel.Application")
xlCells (vlax-get-property
(vlax-get-property
(vlax-get-property
(vlax-invoke-method
(vlax-get-property xlApp "Workbooks")
"Add"
)
"Sheets"
)
"Item"
1
)
"Cells"
)
)
(setq row 1)
(foreach pt lst_data
(setq col 1)
(foreach coor pt
(vlax-put-property xlCells 'Item row col coor)
(setq col (1+ col))
)
(setq row (1+ row))
)
(vla-put-visible xlApp :vlax-true)
(mapcar
(function (lambda (x)
(vl-catch-all-apply
(function (lambda ()
(if x
(vlax-release-object x)
)
)
)
)
)
)
(list xlCells xlApp)
)
(gc)
(gc)
)
(defun WriteToCSV (lst_data / fl)
(if (setq fl (getfiled "Output File" "" "csv" 1))
(if (setq fl (open fl "w"))
(progn
(foreach pt lst_data
(write-line
(LM:lst->str pt ",")
fl
)
)
(close fl)
)
)
)
(princ)
)
;|«Visual LISP© Format Options»
(200 2 60 2 nil "end of " 80 9 0 0 0 T T T T)
;*** DO NOT add text below the comment! ***|;Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ viết Lsp xuất toạ độ tâm block. Xem đúng bài viết #447327 để đọc hướng dẫn và trao đổi thêm.