Lisp lệnh THKL trong chủ đề “Nhờ viết lisp thông kê giá trị trong block ATT”
Mạn phép anh giabach Tue_NV sửa lại chút đỉnh cho phù hợp với y/c của bạn pawuta
(defun c:ThKl (/ doc) (vl-load-com) (princ "\nChon Block can tong hop :") (if (ssget (list (cons 0 "INSERT")(cons 66 1))) (tkatt (vla-get-ActiveSelectionSet (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))) (vla-get-modelspace doc) "DK" "TCD" "TKL" ) (princ "\nKhong chon duoc Block thuoc tinh.")) (princ)) (defun tkatt (ssets msp idTag val1tag val2tag / asoc h i id lst pt row tblobj val1 val2 width) ;; By : Gia_Bach, www.CadViet.com 2015 ;; (vlax-for obj ssets (setq id nil val1 nil val2 nil) (foreach att (vlax-invoke obj 'GetAttributes) (cond ( (= (vla-get-TagString att) idTag) (setq id (vla-get-TextString att)) ) ( (= (vla-get-TagString att) val1Tag) (setq val1 (vla-get-TextString att)) ) ( (= (vla-get-TagString att) val2Tag) (setq val2 (vla-get-TextString att)) ) )) (if (and id (distof id 2) val1 val2(setq val1 (distof val1 2))(setq val2 (distof val2 2))) (if (setq asoc (assoc id lst)) (setq lst (subst (cons id (list (+ val1 (car(cdr asoc))) (+ val2 (cadr(cdr asoc))))) asoc lst)) (setq lst (append lst (list (cons id (list val1 val2)))) )) )) (cond ( (not lst ) (princ "\nKhong tim duoc so lieu.") ) ( (> (atof (substr (getvar "ACADVER") 1 4)) 16.0) (if (setq pt (getpoint "\nDiem dat Bang tong hop:")) (progn (setq h 1.8 width (* 6 h) TblObj (vla-addtable msp (vlax-3d-point pt) (length lst) 4 (* 2 h) width)) (vla-unMergeCells TblObj 0 0 0 3) (vla-put-regeneratetablesuppressed TblObj :vlax-false) (vla-put-vertcellmargin TblObj (* 0.75 h)) (mapcar '(lambda (x)(vla-setTextHeight TblObj x h)) (list acTitleRow acHeaderRow acDataRow) ) (mapcar '(lambda (x)(vla-setAlignment TblObj x 8)) (list acTitleRow acHeaderRow acDataRow)) ;(vla-setText TblObj 0 0 "Bang tong hop") ;(vla-setText TblObj 1 0 "STT") ;(vla-setText TblObj 0 0 idTag) ;(vla-setText TblObj 1 2 val1Tag) ;(vla-setText TblObj 1 3 val2Tag) (setq row 0 i 1) (foreach pt (vl-sort lst '(lambda (x y) (< (car x) (car y)))) (vla-setText TblObj row 0 (itoa i)) (vla-setText TblObj row 1 (car pt)) (vla-setText TblObj row 2 (rtos(car(cdr pt))2 2)) (vla-setText TblObj row 3 (rtos(cadr(cdr pt))2 2)) (setq row (1+ row) i (1+ i)) ) (vla-put-regeneratetablesuppressed TblObj :vlax-false) (vlax-release-object TblObj) ))) ( t (foreach it (vl-sort lst '(lambda (x y) (< (car x) (car y)))) (princ (strcat "\n"(car it) " : " (rtos(car(cdr it))2 2) " : " (rtos(cadr(cdr it))2 2)))) ) ) )
Cảm ơn bạn Tue_NV nhiều nhé, lisp chạy oke rồi, một lần nữa cảm ơn mọi người đã quan tâm tới bài viết. Chỉ còn phần link giá trị nữa là thoả mãn cuộc tình luôn, khi nào các bạn có dịp ghé lại bài viết này thì thêm phần link giá trị nữa nhé! Chúc các bạn luôn thành công trong cuộc sống
- Tải lisp
- 346021_thkl.lsp
Cách dùng
- Tải tệp 346021_thkl.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 THKL để chạy lisp.
Mã nguồn 346021_thkl.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/126869-nh%E1%BB%9D-vi%E1%BA%BFt-lisp-th%C3%B4ng-k%C3%AA-gi%C3%A1-tr%E1%BB%8B-trong-block-att/
(defun c:ThKl (/ doc)
(vl-load-com)
(princ "\nChon Block can tong hop :")
(if (ssget (list (cons 0 "INSERT")(cons 66 1)))
(tkatt (vla-get-ActiveSelectionSet (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))))
(vla-get-modelspace doc) "DK" "TCD" "TKL" )
(princ "\nKhong chon duoc Block thuoc tinh."))
(princ))
(defun tkatt (ssets msp idTag val1tag val2tag / asoc h i id lst pt row tblobj val1 val2 width)
;; By : Gia_Bach, www.CadViet.com 2015 ;;
(vlax-for obj ssets
(setq id nil val1 nil val2 nil)
(foreach att (vlax-invoke obj 'GetAttributes)
(cond
( (= (vla-get-TagString att) idTag)
(setq id (vla-get-TextString att)) )
( (= (vla-get-TagString att) val1Tag)
(setq val1 (vla-get-TextString att)) )
( (= (vla-get-TagString att) val2Tag)
(setq val2 (vla-get-TextString att)) ) ))
(if (and id (distof id 2) val1 val2(setq val1 (distof val1 2))(setq val2 (distof val2 2)))
(if (setq asoc (assoc id lst))
(setq lst (subst (cons id (list (+ val1 (car(cdr asoc))) (+ val2 (cadr(cdr asoc))))) asoc lst))
(setq lst (append lst (list (cons id (list val1 val2)))) )) ))
(cond
( (not lst )
(princ "\nKhong tim duoc so lieu.") )
( (> (atof (substr (getvar "ACADVER") 1 4)) 16.0)
(if (setq pt (getpoint "\nDiem dat Bang tong hop:"))
(progn
(setq h 1.8 width (* 6 h)
TblObj (vla-addtable msp (vlax-3d-point pt) (length lst) 4 (* 2 h) width))
(vla-unMergeCells TblObj 0 0 0 3)
(vla-put-regeneratetablesuppressed TblObj :vlax-false)
(vla-put-vertcellmargin TblObj (* 0.75 h))
(mapcar '(lambda (x)(vla-setTextHeight TblObj x h))
(list acTitleRow acHeaderRow acDataRow) )
(mapcar '(lambda (x)(vla-setAlignment TblObj x 8))
(list acTitleRow acHeaderRow acDataRow))
;(vla-setText TblObj 0 0 "Bang tong hop")
;(vla-setText TblObj 1 0 "STT")
;(vla-setText TblObj 0 0 idTag)
;(vla-setText TblObj 1 2 val1Tag)
;(vla-setText TblObj 1 3 val2Tag)
(setq row 0 i 1)
(foreach pt (vl-sort lst '(lambda (x y) (< (car x) (car y))))
(vla-setText TblObj row 0 (itoa i))
(vla-setText TblObj row 1 (car pt))
(vla-setText TblObj row 2 (rtos(car(cdr pt))2 2))
(vla-setText TblObj row 3 (rtos(cadr(cdr pt))2 2))
(setq row (1+ row) i (1+ i)) )
(vla-put-regeneratetablesuppressed TblObj :vlax-false)
(vlax-release-object TblObj) )))
( t
(foreach it (vl-sort lst '(lambda (x y) (< (car x) (car y))))
(princ (strcat "\n"(car it) " : " (rtos(car(cdr it))2 2) " : " (rtos(cadr(cdr it))2 2)))) ) )
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ viết lisp thông kê giá trị trong block ATT. Xem đúng bài viết #346021 để đọc hướng dẫn và trao đổi thêm.