;; c:AAA () Select-1: Lwpoyline >> Select-2: RoomName >> RoomName: 1234.56m2 (789PY)
;; c:RNN () Select Area_Tag: RoomName: 1234.56m2 (789PY) >> RoomName
;; c:CSV () Select Area_Tags >> Put Total Area >> "\t", "=SUM(C2:Cn)" included CSV
;;===================ROOM NAME AREA=======================
;; Author: KM Lab, Copyright © 2021 - kmlab.tistory.com
;; Version 1.0 - 2021-09-06
;; Version 1.01 - 2021-11-02
(defun KM:area_lwp ( / e id area m2area )
(setq PY 0.3025)
(setq e (entget (car (entsel "\n SELECT LWPOLYLINE: \n"))))
(setq id (cdr (assoc -1 e)))
(setq area (vlax-curve-getArea id))
(setq m2area (* 1.0e-06 area))
(setq _M2 (strcat ": " (rtos m2area 2 2) "m2"));
(setq _PY (strcat " (" (rtos (* m2area PY) 2 1) "PY)"));
(princ)
);defun
(defun KM:RmAreaX ( _M2 / txt_lst rmname exist_m2 rmarea)
(setq txt_lst (entget (car (entsel "\n SELECT ROOMNAME: \n"))))
(setq rmname (cdr (assoc 1 txt_lst)))
(if (/= nil (setq exist_m2 (vl-string-search ":" rmname)))
(progn
(setq rmname
(substr rmname 1 exist_m2)));progn
);if it exists the area, extract it's the room name in the rmname to update new area.
(setq rmarea (cons 1 (strcat rmname _M2 _PY)))
(entmod (subst rmarea (assoc 1 txt_lst) txt_lst))
(princ)
);defun
(defun c:AAA ( )
(KM:area_lwp)
(KM:RmAreaX _M2)
);defun
;===================Extract ROOM NAME=======================
;; Author: KM Lab, Copyright © 2021 - kmlab.tistory.com
;; Version 1.0 - 2021-11-02
;; RoomName: 1234.56m2\t(789PY) >> get RoomName
(defun KM:ExtRoomName ( / )
(setq txt_lst (entget (car (entsel "\n SELECT ROOMNAME: \n"))))
(setq rmname (cdr (assoc 1 txt_lst)))
(setq exist_m2 (vl-string-search ":" rmname))
(setq rmname (substr rmname 1 exist_m2))
(setq rnn (cons 1 rmname))
(entmod (subst rnn (assoc 1 txt_lst) txt_lst))
(princ)
);defun
(defun c:rnn ( )
(KM:ExtRoomName)
);defun
;;===================TXTs to csvfile=======================
;; "RoomName: \t1234.56m2\t(789PY)" >> c:\temp\area.csv
;; Author: KM Lab, Copyright © 2021 - kmlab.tistory.com
;; Version 1.0 - 2021-09-06
;; Version 1.01 - 2021-11-02
;; Separator is "\t"
;; added HEADER "No.\tName\tAREA\t(PY)" for Excel
;; added FOOTER "\tTOTAL\t=SUM(c2:c[rmno])" for function of Excel
;; rmno is Room No. >> SUM=(Row C2~ Row C[RoomCount])
(defun KM:CSV ( / pt1 txt_lst txts str rm_area_m2 rm_area n_rm_area len n style_ size_ csvfile file_w HEADER FOOTER SUM_)
(setq _LISTXT ( ))
;
(prompt "\nSELECT TXTs: \n")
(setq txts (ssget "c" (setq pt1 (getpoint)) (getcorner pt1) '((0 . "text"))))
(setq len (sslength txts))
(setq n 0)
(setq rmno 1)
;
(setq csvfile "c:/temp/area.csv")
(setq file_w (open csvfile "w"))
(setq HEADER "No.\tRoomName\tAREA\t(PY)")
;;
(write-line HEADER file_w)
;
(setq _AREA 0.0)
(repeat len
(setq txt_lst (entget (ssname txts n)))
(setq str (cdr (assoc 1 txt_lst)))
(if (and (vl-string-search ":" str) (vl-string-search "m2\t" str))
(progn
;; Extract AREA from str
(setq loc_split (+ 3 (vl-string-search ":" str)))
(setq _AREA (+ _AREA (atof (substr str loc_split (- (strlen str) (+ loc_split 1))))))
;;
(setq rm_area_m2 (vl-string-subst "\t" ":" str))
(setq rm_area (vl-string-subst "" "m2" rm_area_m2))
(setq n_rm_area (strcat (itoa rmno) "\t" rm_area))
;;
(write-line n_rm_area file_w)
(setq rmno (+ 1 rmno))
);progn
);if
(setq n (1+ n))
);repeat
(setq SUM_ (strcat "=SUM(c2:c" (itoa rmno) ")"))
(setq FOOTER (strcat "\tTOTAL\t" SUM_))
(write-line FOOTER file_w)
(setq style_ (cdr (assoc 7 (entget (ssname txts 0)))))
(setq size_ (cdr (assoc 40 (entget (ssname txts 0)))))
;(princ (setq _TOTAL (strcat "\n" (getvar "CLAYER") "_TOTAL AREA: " (rtos _AREA 2 2) "m2\n")))
(princ (setq _TOTAL (strcat "\nTOTAL AREA: " (rtos _AREA 2 2) "m2\t(" (rtos (* _AREA 0.3025) 2 1) "PY)\n")))
(prompt "\n>> Specify Insertion point of the Total Area...\n")
(entmake (list (cons 0 "TEXT") (cons 1 _TOTAL) (cons 7 style_) (cons 10 (getpoint)) (cons 40 size_)))
(princ _AREA)
;
(close file_w)
(princ "\n")
(princ)
);defun
(defun c:csv ()
(KM:CSV)
);defun
'autocad' 카테고리의 다른 글
temporary FILLET 0; start EXPLORER current dwg folder (0) | 2021.12.16 |
---|---|
DWG to PDF(A3) Updates (0) | 2021.12.15 |
DWG to PDF.pc3, c:KP (0) | 2021.10.27 |
XREF BIND, c:XRX, c:XRR, c:REE (0) | 2021.10.27 |
접두사 접미사 추가, c:psx (0) | 2021.10.07 |