Lisp lệnh IMF trong chủ đề “Viết lisp theo yêu cầu [phần 2]”
Vừa post xong thì nghĩ lại, thấy cũng không phức tạp lắm.
Phiphi thử lisp cải tiến dưới đây
- Tải lisp
- 90849_imf.lsp
Cách dùng
- Tải tệp 90849_imf.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 IMF để chạy lisp.
Mã nguồn 90849_imf.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/13203-vi%E1%BA%BFt-lisp-theo-y%C3%AAu-c%E1%BA%A7u-ph%E1%BA%A7n-2/?page=40&tab=comments#comment-90892
(defun c:imf ()
(defun sosanh (a b )
(defun ne (s)
(atoi (vl-list->string
(vl-remove-if
'(lambda (x) (or ( x 57)))
(vl-string->list s)
)
)
)
)
( )
(setq pathname (vl-filename-directory
(getfiled "Hay chon file dwg bat ky thuoc thu muc"
""
"dwg"
0
)
)
filelist (vl-sort (vl-directory-files pathname "*.dwg") 'sosanh)
p (getpoint "\nDiem chen: ")
xht (car p)
yht (cadr p)
)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(foreach filename filelist
(command "-insert"
(strcat pathname "/" filename)
(list xht yht)
1.0
1.0
0.0
)
(vla-getboundingbox
(vlax-ename->vla-object (entlast))
'p1
'p2
)
(setq
p1 (vlax-safearray->list p1)
p2 (vlax-safearray->list p2)
xht (+ xht (abs (car (mapcar '- p2 p1))))
blname (cdr (assoc 2 (entget (entlast))))
)
(command ".explode" (entlast) "")
(command "-purge" "Block" blname "N")
)
(setvar "osmode" oldos)
(princ)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề Viết lisp theo yêu cầu [phần 2]. Xem đúng bài viết #90849 để đọc hướng dẫn và trao đổi thêm.