Jump to content

Lisp lệnh CHATTCSV trong chủ đề “Edit trực tiếp text Attribute trong block”


Trong khi chờ đợi Thaistreet, các bạn dùng ví dụ về file *.csv này thử:
https://www.cadviet.com/upfiles/2/ttattribute.zip
trong file *.csv này có 6 hàng dữ liệu tương ứng với 6 blockref, các bạn copy block khungten thêm 5 nữa,
Khi lisp yêu cầu: Select objects, các bạn dùng chế độ chọn là fence "f", làm như vậy để đối tượng nào dính fence trước sẽ được lisp xử lý trước,
Còn đây là file lisp:
Chúc các bạn thành công!!!

Cách dùng

  1. Tải tệp 75637_chattcsv.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 CHATTCSV để chạy lisp.

Mã nguồn 75637_chattcsv.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/13970-edit-tr%E1%BB%B1c-ti%E1%BA%BFp-text-attribute-trong-block/
;| Lisp thay doi gia tri thuoc tinh cua cac block reference
            CHANGE-ATTRIB.LSP V1:  10-2009                
---------------------------------------------------------|;
(defun serapate	(row sym /  st1 row)
 (setq L nil)
 (while (setq vitri (vl-string-search sym row 1))
   (setq st1 (substr row 1 vitri))
   (setq L (append L (list st1)))
   (setq row (vl-string-left-trim st1 row))
   (setq row (vl-string-left-trim sym row))
 )
 (append L (list row))
)
(defun SS-enlst	(ss / c L)
 (setq c -1)
 (repeat (sslength ss)
   (setq L (cons (ssname ss (setq c (1+ c))) L))
 )
 (reverse L)
)
(defun getatt (itm)
 (vlax-safearray->list
   (vlax-variant-value
     (vla-GetAttributes itm)
   )
 )
)

;;;-----------------------------------------------------------
(vl-load-com)
;;;------- Main Program -----------
(defun c:chattCSV (/ fn f L blSet objbl attLst i n m)
 (setq fn (getfiled "Select data file" "c:/" "csv" 0))
 (setq f (open fn "r"))
 (read-line f)
 (princ "<<< Select blocks to change attributes >>>")
 (if (setq blSet (ssget '((0 . "INSERT") (66 . 1))))
   (setq blSet (mapcar 'vlax-ename->vla-object (SS-enlst blSet)))
 )
 (setq	n 0
m (length blSet))
 (while (and (setq S (read-line f)) (< n m))
   (setq L	 (serapate S ",")
  objbl	 (nth n blSet)
  attLst (getatt objbl)
  i	 0
   )
   (foreach att attLst
     (vla-put-textstring att (nth i L))
     (setq i (1+ i))
   )
   (setq n (1+ n))
 )
 (cond ((and (< n m) (not (read-line f)))
 (alert "\nThe Numbers of blocksrefs more than the numbers of data rows.
	\n                   Finish input data from file. ")
 )
((read-line f)
  (alert
    "\nThe Numbers of data rows more than the numbers of blocksrefs.
    \n                    Finish input data from file. "
  )
)
(t (alert "\n             Lisp's mission accomplished !
	  \n              Finish input data from file.
	  \nTHANK YOU FOR USE LISP CHANGE ATTRIBUTES FOR BLOCKS. THIEP"))
 )
 (close f)
 (princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Edit trực tiếp text Attribute trong block. Xem đúng bài viết #75637 để đọc hướng dẫn và trao đổi thêm.

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