;; AutoCAD에서 작업된 표를 CSV 파일로 저장.
;; 하나의 셀에서 하나의 문자만 가져옴.
;; 하나의 셀에 있는 여러문자를 하나의 문자열로 저장할 필요가 있음.
;; 2021/09/08 by Sean Lee @KM_Lab
;; 2021/09/14 by Sean Lee @KM_Lab. 여러문자 한셀에 저장. KM:get_strS
(defun LM:Unique ( l ); @LeeMacLISP
(if l (cons (car l) (LM:Unique (vl-remove (car l) (cdr l)))))
);defun
;
(defun KM:sel_tbl ( / P1 P2 )
(prompt "\nSelect Table by Window")
(setq P1 (getpoint "\nFirst Corner: "))
(setq P2 (getcorner p1 "\nSecond Corner: "))
(setq seltbl1
(ssget "c" P1 P2
'((-4 . "<OR")(0 . "LINE")
(-4 . "<AND")(0 . "LWPOLYLINE")(-4 . "<")(90 . 5)
(-4 . "AND>")
(-4 . "OR>"))
))
);defun
;
(defun KM:ratio_box ( PT1 PT2 / ratio pt1x pt1y pt2x pt2y lx ly )
(setq ratio 0.8)
(setq pt1x (car PT1) pt1y (cadr PT1) pt2x (car PT2) pt2y (cadr PT2))
(setq lx (- pt2x pt1x) ly (- pt2y pt1y))
(setq _CP1 (list (+ pt1x (* lx (- 1.0 ratio))) (+ pt1y (* ly (- 1.0 ratio)))))
(setq _CP2 (list (+ pt1x (* lx ratio)) (+ pt1y (* ly ratio))))
);defun
;
;;KM:get_strS
(defun KM:get_strS ( PT1 PT2 / txtobj t_x t_str t_xstr t_srt cstr )
(km:ratio_box PT1 PT2)
(setq txts (ssget "c" _CP1 _CP2 '((0 . "TEXT"))))
(if (= nil (not txts))
(progn
(setq len (sslength txts))
(setq _CELLSTR "")
(setq t_xstr '( ))
(setq n 0)
(repeat len
(setq txtobj (entget (ssname txts n)));get entity zero from prop.
(setq t_x (car (cdr (assoc 10 txtobj))))
(setq t_str (cdr (assoc 1 txtobj))); get list text string
(setq t_xstr (append t_xstr (list (list t_x t_str))))
(setq n (1+ n))
);repeat
(setq t_srt (vl-sort t_xstr
(function
(lambda (x1 x2)(< (car x1) (car x2)))
)
))
(setq m 0)
(repeat len
(setq cstr (car (cdr (nth m t_srt))))
(setq _CELLSTR (strcat _CELLSTR cstr " " ))
(setq m (1+ m))
);repeat
(setq _CELLSTR (substr _CELLSTR 1 (- (strlen _CELLSTR) 1))); remove the Last Space
);progn
(setq _CELLSTR ""); set list blank
);if
);defun
;
(defun KM:pt_lwp ( EN / e len n e1 coord_lwp )
(setq coord_lwp '( ))
(setq e EN)
(setq len (length e))
(setq n 0)
(repeat len
(setq e1 (car (nth n e)))
(if (= e1 10); Vertext of lwpolyline
(progn
(setq coord_lwp (append coord_lwp (list (cdr (nth n e)))))
);progn
);if
(setq n (1+ n))
);repeat
(setq coord_lst coord_lwp)
);defun
;
(defun KM:pt_ln ( EN / e sp ep )
(setq coord_lst '( ))
(setq e EN)
(setq sp (list (car (cdr (assoc 10 e))) (car (cdr (cdr (assoc 10 e))))))
(setq ep (list (car (cdr (assoc 11 e))) (car (cdr (cdr (assoc 11 e))))))
(setq coord_lst (list sp ep))
);defun
;
(defun KM:xycoords ( COORD_LST / xcoords_lst ycoords_lst len n )
(setq _XCOORDS '( ))
(setq _YCOORDS '( ))
(setq xcoords_lst '( ))
(setq ycoords_lst '( ))
(setq len (length COORD_LST))
(setq n 0)
(repeat len
(setq xcoords_lst (append xcoords_lst (list (atof (rtos (car (nth n COORD_LST)) 2 1)))))
(setq ycoords_lst (append ycoords_lst (list (atof (rtos (cadr (nth n COORD_LST)) 2 1)))))
(setq n (1+ n))
);repeat
(setq _XCOORDS (vl-sort (lm:unique xcoords_lst) '<))
(setq _YCOORDS (vl-sort (lm:unique ycoords_lst) '>))
);defun
;
(defun KM:tbl2cds ( / lns len n ln xps yps row col _PT1 _PT2 )
(setq coord_lst '( ))
(setq xcoords_lst '( ))
(setq ycoords_lst '( ))
(setq lns (KM:sel_tbl))
(setq len (sslength lns))
(setq n 0)
(repeat len
(setq ln (entget (ssname lns n)))
(if (= "LWPOLYLINE" (cdr (assoc 0 ln)))
(progn
(setq coord_lst (append coord_lst (KM:pt_lwp ln)))
);progn
(progn
(setq coord_lst (append coord_lst (KM:pt_ln ln)))
);progn
);if
(setq n (1+ n))
);repeat
(setq _COORDS coord_lst)
);defun
;
(defun c:tbl2csv ( / osmd _Xs _Ys row col nrow ncol x1 x2 y1 y2 getstr str_line)
(setq osmd (getvar "OSMODE"))
(setvar "OSMODE" 0)
(KM:tbl2cds)
(KM:xycoords _COORDS)
(setq _Xs _XCOORDS _Ys _YCOORDS)
(setq row (- (length _Ys) 1))
(setq col (- (length _Xs) 1))
(setq nrow 0)
(setq csvfile "c:/temp/tbl2csv.csv")
(setq file_w (open csvfile "w"))
(repeat row
(setq y1 (nth nrow _Ys))
(setq y2 (nth (1+ nrow) _Ys))
(setq ncol 0)
(setq str_line " ")
(repeat col
(setq x1 (nth ncol _Xs))
(setq x2 (nth (1+ ncol) _Xs))
(setq _p1 (list x1 y1) _p2 (list x2 y2))
(setq getstr (KM:get_strs _p1 _p2))
(setq str_line (strcat str_line "\t" getstr))
(setq ncol (1+ ncol))
);repeat
(setq str_line (strcat (itoa nrow) str_line))
(write-line str_line file_w)
(setq nrow (1+ nrow))
);repeat
(close file_w)
(princ "\n")
(setvar "OSMODE" osmd)
);defun
'autocad' 카테고리의 다른 글
Developed Apps until 202109 (0) | 2021.09.15 |
---|---|
Automatically Number (0) | 2021.09.09 |
TXT2CSV (0) | 2021.09.06 |
Room Area (0) | 2021.09.06 |
\n (0) | 2021.09.01 |