Lisp gộp Hatch Pattern
Lisp add toàn bộ Hatch Pattern trong các file PAT từ 1 thư mục (và các thư mục con) vào bảng Hatch của CAD
- Tải lisp
- 168515_add-hatch.lsp
Cách dùng
- Tải tệp 168515_add-hatch.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 ADD-HATCH để chạy lisp.
Mã nguồn 168515_add-hatch.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/54190-%C4%91%C3%A3-xong-lisp-g%E1%BB%99p-hatch-pattern/
(defun c:Add-Hatch( / ST:UI-Nil-Alert ST:File_GetAll Browse patFolder lstFiles isoFile iso1File pat1 pat2)
;@ Ketxu 13 - 9 - 11
; Add Hatch to Acad, Acadiso.pat
(grtext -1 "Assign Hatch Pattern Working ! @Ketxu ")
; =====================================================
; ============= Local Function ========================
; =====================================================
;| ======= ST:UI-Nil-Alert ============================
Alert if a value in LIST is Nil
Base on pBe CADTUTOR
@Ketxu 14 - 9 - 11
|;
(defun ST:UI-Nil-Alert ( msgDefault lst / x )
(if (setq x (vl-some '(lambda ( x ) (if (null (eval (car x))) (cadr x))) lst))
(alert (strcat msgDefault x))
)
)
;| ======= ST:File_GetAll =============================
Get all Files in subs Directory by match
Base on Lee Mac
@Ketxu 14 - 9 - 11
|;
(defun ST:File_GetAll ( Dir typ )
(append (mapcar '(lambda ( x ) (strcat Dir "\\" x)) (vl-directory-files Dir typ 1))
(apply 'append
(mapcar '(lambda ( x ) (ST:File_GetAll (strcat dir "\\" x) typ))
(cddr (vl-directory-files dir "*" -1))
)
)
)
)
;| ======= Browse =====================================
Get folder UI
@ Lee Mac
|;
(defun Browse ( msg dir flag / Shell Fold Self Path ) ;@Lee Mac
(vl-catch-all-apply
(function
(lambda ( / ac HWND )
(if
(setq Shell (vla-getInterfaceObject (setq ac (vlax-get-acad-object)) "Shell.Application")
HWND (vl-catch-all-apply 'vla-get-HWND (list ac))
Fold (vlax-invoke-method Shell 'BrowseForFolder (if (vl-catch-all-error-p HWND) 0 HWND) msg flag dir)
)
(setq Self (vlax-get-property Fold 'Self)
Path (vlax-get-property Self 'Path)
Path (vl-string-right-trim "\\" (vl-string-translate "/" "\\" Path))
)
)
)
)
)
(if Self (vlax-release-object Self))
(if Fold (vlax-release-object Fold))
(if Shell (vlax-release-object Shell))
Path
)
; =====================================================
; ============ Start Rountine =========================
; =====================================================
(cond
((and
(setq patFolder (Browse "Select Folder Contains PAT File : \n\t(Work With Sub Folder Also)" nil 0))
(setq lstFiles (ST:File_GetAll patFolder "*.PAT"))
(setq isoFile (open (setq pat1 (findfile "acadiso.pat")) "a"))
(setq iso1File (open (setq pat2 (findfile "acad.pat")) "a"))
)
(mapcar '(lambda(x)
(setq tmpOpen (open x "r"))
(while (setq Line (read-line tmpOpen))
(write-line Line isoFile)
(write-line Line iso1File)
)
(close tmpOpen)
)
lstFiles
)
(close isoFile)
(close iso1File)
(initget "Y N y n")
(setq ans (getkword "B\U+1EA1n c\U+00F3 mu\U+1ED1n l\U+01B0u l\U+1EA1i file PAT th\U+00EAm 1 b\U+1EA3n kh\U+00E1c ? [Y / N]"))
(cond ((= ans "Y")
(if(setq patSave (getfiled "File name to save ?" "PAT_back" "pat" 1))
(and (vl-file-copy pat1 (strcat (vl-string-right-trim ".pat" patSave) "-1.pat"))
(vl-file-copy pat2 (strcat (vl-string-right-trim ".pat" patSave) "-2.pat"))
)
)
)
)
(alert "Qu\U+00E1 tr\U+00ECnh th\U+00EAm Hatch \U+0111\U+00E3 ho\U+00E0n t\U+1EA5t.\nC\U+00E1c Hatch Pattern \U+0111\U+00E3 \U+0111\U+01B0\U+1EE3c th\U+00EAm v\U+00E0o m\U+1EE5c Other Predefined !!")
)
(T (ST:UI-Nil-Alert "Qu\U+00E1 tr\U+00ECnh th\U+00EAm Hatch Pattern b\U+1ECB l\U+1ED7i !\n"
'((patFolder "B\U+1EA1n ch\U+01B0a ch\U+1ECDn th\U+01B0 m\U+1EE5c ch\U+1EE9a file PAT")
(lstFiles "Trong th\U+01B0 m\U+1EE5c b\U+1EA1n ch\U+1ECDn (v\U+00E0 c\U+00E1c th\U+01B0 m\U+1EE5c con) kh\U+00F4ng ch\U+1EE9a file PAT n\U+00E0o")
(isoFile "Kh\U+00F4ng t\U+00ECm th\U+1EA5y file acadiso.pat")
(iso1File "Kh\U+00F4ng t\U+00ECm th\U+1EA5y file acad.pat")
)
)
)
)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Đã xong] Lisp gộp Hatch Pattern. Xem đúng bài viết #168515 để đọc hướng dẫn và trao đổi thêm.