Lisp lệnh AAA trong chủ đề “[Nhờ giúp đỡ] Chuyển xref thành no path”
Nhờ các bác sửa cho em đoạn code này, mục đích là chuyển xref thành no path. Có lẽ lisp không update dữ liệu vào được nên không chạy. Em đang gặp khó khăn nếu reference name bị thay đổi (không trùng tên với file xref).
(defun c:aaa(/ tmp1)
;(vl-load-com)
(setq tmp1 (tblnext "BLOCK" 1))
(WHILE (/= tmp1 NIL)
(IF(/= (assoc 1 tmp1) nil)
(PROGN
(SETQ xfname (cdr (ASSOC 2 tmp1)))
(princ xfname) (princ "\n Current: ")
(setq pathname (cdr (assoc 1 tmp1)))
(princ pathname)
(setq ct (strlen pathname))
(setq c ct)
(setq test (substr pathname ct 1))
(while (/= test "\\")
(setq test (substr pathname c 1))
(setq c (1- c))
) ;while
(setq pathdir (substr pathname 1 c))
(setq filenameex (substr pathname (1+ c)))
(if (/= (assoc 2 tmp1) (substr pathname 1 (- (strlen pathname) 4)))
(progn
(setq tmp1 (subst (cons 1 (strcat (cdr (assoc 2 tmp1)) ".dwg")) (assoc 1 tmp1) tmp1))
(entmod tmp1)
(entupd (cdr(assoc -2 tmp1)))
)
))))
(setq tmp1 (tblnext "BLOCK"))
)
(defun c:aaa(/ tmp1)
;(vl-load-com)
(setq tmp1 (tblnext "BLOCK" 1))
(WHILE (/= tmp1 NIL)
(IF(/= (assoc 1 tmp1) nil)
(PROGN
(SETQ xfname (cdr (ASSOC 2 tmp1)))
(princ xfname) (princ "\n Current: ")
(setq pathname (cdr (assoc 1 tmp1)))
(princ pathname)
(setq ct (strlen pathname))
(setq c ct)
(setq test (substr pathname ct 1))
(while (/= test "\\")
(setq test (substr pathname c 1))
(setq c (1- c))
) ;while
(setq pathdir (substr pathname 1 c))
(setq filenameex (substr pathname (1+ c)))
(if (/= (assoc 2 tmp1) (substr pathname 1 (- (strlen pathname) 4)))
(progn
(setq tmp1 (subst (cons 1 (strcat (cdr (assoc 2 tmp1)) ".dwg")) (assoc 1 tmp1) tmp1))
(entmod tmp1)
(entupd (cdr(assoc -2 tmp1)))
)
))))
(setq tmp1 (tblnext "BLOCK"))
)
Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.
Cách dùng
- Chép mã nguồn, lưu thành tệp 201801_aaa.lsp.
- 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 AAA để chạy lisp.
Mã nguồn 201801_aaa.lsp (trích từ bài viết gốc)
(defun c:aaa(/ tmp1)
;(vl-load-com)
(setq tmp1 (tblnext "BLOCK" 1))
(WHILE (/= tmp1 NIL)
(IF(/= (assoc 1 tmp1) nil)
(PROGN
(SETQ xfname (cdr (ASSOC 2 tmp1)))
(princ xfname) (princ "\n Current: ")
(setq pathname (cdr (assoc 1 tmp1)))
(princ pathname)
(setq ct (strlen pathname))
(setq c ct)
(setq test (substr pathname ct 1))
(while (/= test "\\")
(setq test (substr pathname c 1))
(setq c (1- c))
) ;while
(setq pathdir (substr pathname 1 c))
(setq filenameex (substr pathname (1+ c)))
(if (/= (assoc 2 tmp1) (substr pathname 1 (- (strlen pathname) 4)))
(progn
(setq tmp1 (subst (cons 1 (strcat (cdr (assoc 2 tmp1)) ".dwg")) (assoc 1 tmp1) tmp1))
(entmod tmp1)
(entupd (cdr(assoc -2 tmp1)))
)
))))
(setq tmp1 (tblnext "BLOCK"))
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Nhờ giúp đỡ] Chuyển xref thành no path. Xem đúng bài viết #201801 để đọc hướng dẫn và trao đổi thêm.