Jump to content

Lisp lệnh AUTOLOADALLLISPS trong chủ đề “NẠP ĐẠN (.LSP) CHO STARTUP SUITE ĐỂ "BẮN"”

28 phút trước, duy782006 đã nói:

Túm lại là bạn biết làm rồi và đang đố mọi người hay là bãn muốn vậy và đang hỏi mọi người cách làm?

Cái này có gì mà đánh đố đâu anh. Em thấy các tiền bối đã làm nhiều rồi, tra theo từ khóa là ra. Của em cùng toàn cóp nhặt rồi edit lại chứ có gì đâu.

Giờ rảnh ngồi máy gửi code em chế lại thôi chứ cũng không đủ khả năng viết:

(vl-load-com)
;; Add Support File Search Paths  -  Lee Mac
;; Adds a list of Support File Search Paths, excluding duplicates and invalid paths.
;; lst -  list of paths to add, e.g. '("C:\\Folder1" "C:\\Folder2" ... )
;; Returns:  "ACAD" Environment String following modification
;; (LM:sfsp+ <lst>)
;; (LM:sfsp+ '("C:\\Folder1" "C:\\Folder2" "C:\\Folder3"))

(defun LM:sfsp+ ( lst )
    (   (lambda ( str lst )
            (if (setq lst
                    (vl-remove-if
                       '(lambda ( x )
                            (or (vl-string-search (strcase x) (strcase str))
                                (not (findfile x))
                            )
                        )
                        lst
                    )
                )
                (setenv "ACAD" (strcat str ";" (apply 'strcat (mapcar '(lambda ( x ) (strcat x ";")) lst))))
            )
        )
        (vl-string-right-trim ";" (getenv "ACAD"))
        (mapcar '(lambda ( x ) (vl-string-right-trim "\\" (vl-string-translate "/" "\\" x))) lst)
    )
)
;======================================================================================================================
(defun c:AutoLoadAllLisps ( / lst pth x dir )
  (princ "\nAutoRun AutoLoadAllLisps Programs!")
  (if (not (findfile "AutoLoadAllLisps.lsp"))
	(progn
	(setq dir (acet-ui-pickdir "" "" "Ch\U+1ECDn th\U+01B0 m\U+1EE5c ch\U+1EE9a t\U+1EC7p AutoLoadAllLisps.lsp")); de them vao Support File Search Path cua AutoCad"
	(setq dirtv (strcat dir "\\" "Thu vien"))
	(setq dirlk (strcat dir "\\" "Lisp khac"))
	(LM:sfsp+ (list dir dirtv dirlk));Ham them thu muc va SFSP cua AutoCad cua Lee Mac
	(setenv "PrinterStyleSheetDir" dirtv)
	);end progn
  )
  (setq pth (findfile "AutoLoadAllLisps.lsp"))
  (setq pth (vl-string-right-trim "AutoLoadAllLisps.lsp" pth))
  (setq lst (vl-directory-files pth "*.vlx" 1))
  (setq lst (append lst (vl-directory-files pth "*.fas" 1)))
  (setq lst (append lst (vl-directory-files pth "*.lsp" 1)))
  (setq lst (vl-remove "AutoLoadAllLisps.lsp" lst)) 
  (foreach x lst (load x))
  (princ "\nProgram AutoLoadAllLisps was Written by KLN!")
  (princ)
)
;======================================================================================================================
; AutoRun AutoLoadAllLisps Programs when Open AutoCad if Add this programs in Startup Suite in Appload!!!
(c:AutoLoadAllLisps)

 

Cách dùng

  1. Tải tệp 455302_autoloadalllisps.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 AUTOLOADALLLISPS để chạy lisp.

Mã nguồn 455302_autoloadalllisps.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/186059-n%E1%BA%A1p-%C4%91%E1%BA%A1n-lsp-cho-startup-suite-%C4%91%E1%BB%83-b%E1%BA%AFn/
(vl-load-com)
;; Add Support File Search Paths  -  Lee Mac
;; Adds a list of Support File Search Paths, excluding duplicates and invalid paths.
;; lst - [lst] list of paths to add, e.g. '("C:\\Folder1" "C:\\Folder2" ... )
;; Returns: [str] "ACAD" Environment String following modification
;; (LM:sfsp+ <lst>)
;; (LM:sfsp+ '("C:\\Folder1" "C:\\Folder2" "C:\\Folder3"))

(defun LM:sfsp+ ( lst )
    (   (lambda ( str lst )
            (if (setq lst
                    (vl-remove-if
                       '(lambda ( x )
                            (or (vl-string-search (strcase x) (strcase str))
                                (not (findfile x))
                            )
                        )
                        lst
                    )
                )
                (setenv "ACAD" (strcat str ";" (apply 'strcat (mapcar '(lambda ( x ) (strcat x ";")) lst))))
            )
        )
        (vl-string-right-trim ";" (getenv "ACAD"))
        (mapcar '(lambda ( x ) (vl-string-right-trim "\\" (vl-string-translate "/" "\\" x))) lst)
    )
)
;======================================================================================================================
(defun c:AutoLoadAllLisps ( / lst pth x dir )
  (princ "\nAutoRun AutoLoadAllLisps Programs!")
  (if (not (findfile "AutoLoadAllLisps.lsp"))
	(progn
	(setq dir (acet-ui-pickdir "" "" "Ch\U+1ECDn th\U+01B0 m\U+1EE5c ch\U+1EE9a t\U+1EC7p AutoLoadAllLisps.lsp")); de them vao Support File Search Path cua AutoCad"
	(setq dirtv (strcat dir "\\" "Thu vien"))
	(setq dirlk (strcat dir "\\" "Lisp khac"))
	(LM:sfsp+ (list dir dirtv dirlk));Ham them thu muc va SFSP cua AutoCad cua Lee Mac
	(setenv "PrinterStyleSheetDir" dirtv)
	);end progn
  )
  (setq pth (findfile "AutoLoadAllLisps.lsp"))
  (setq pth (vl-string-right-trim "AutoLoadAllLisps.lsp" pth))
  (setq lst (vl-directory-files pth "*.vlx" 1))
  (setq lst (append lst (vl-directory-files pth "*.fas" 1)))
  (setq lst (append lst (vl-directory-files pth "*.lsp" 1)))
  (setq lst (vl-remove "AutoLoadAllLisps.lsp" lst)) 
  (foreach x lst (load x))
  (princ "\nProgram AutoLoadAllLisps was Written by KLN!")
  (princ)
)
;======================================================================================================================
; AutoRun AutoLoadAllLisps Programs when Open AutoCad if Add this programs in Startup Suite in Appload!!!
(c:AutoLoadAllLisps)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề NẠP ĐẠN (.LSP) CHO STARTUP SUITE ĐỂ "BẮN". Xem đúng bài viết #455302 để đọc hướng dẫn và trao đổi thêm.

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