안녕하세요
질문인데요
현재는시트1에출력이되는데요
시트3에출력이되게하려합니다
Text to Excel
;; Made By………. TaeEun -_-)=b
;;
;; Contact Me……. arin9916@naver.com
;; … http://cafe.naver.com/ptelisp
;; Client……….. Gocad
;; Date…………. 2012-04-15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:aa( / objs doc tol excel cell str x y PTE:sortobj LM:UnFormat)
; Sub-function – 01
(defun PTE:sortobj
( olst typ tol /
typ objs opt npt lst data lst rev sx sy dxf x y
PTE:s1 PTE:s2 PTE:s3 PTE:s4
)
(defun rev (ls f) (mapcar ‘(lambda (l)(if (setq f (not f)) (reverse l) l)) ls))
(defun sx (objs) (vl-sort objs ‘(lambda (a b) (< (x a) (x b)))))
(defun sy (objs) (vl-sort objs ‘(lambda (a b) (< (y a) (y b)))))
(defun dxf (o c) (cdr (assoc c (entget (vlax-vla-object->ename o)))))
(defun x (o) (car (dxf o 10)))
(defun y (o) (cadr (dxf o 10)))
(setq typ (vl-string->list (strcase typ)))
(if (member (car typ) ‘(76 82))
(setq PTE:s1 sy PTE:s2 y PTE:s3 sx PTE:s4 rev)
(setq PTE:s1 sx PTE:s2 x PTE:s3 sy PTE:s4 rev)
)
(setq objs (PTE:s1 olst) opt (PTE:s2 (car objs)))
(foreach o objs
(if (< tol (abs (- (setq npt (PTE:s2 o)) opt)))
(setq lst (cons data lst) data (list o) opt npt)
(setq data (cons o data))
)
)
(setq lst (mapcar ‘(lambda (l) (PTE:s3 l))(cons data lst))
lst (if (member (cadr typ) ‘(85 82)) (reverse lst) lst)
lst (if (member (car typ) ‘(68 76)) (mapcar ‘(lambda (l) (reverse l)) lst) lst)
lst (if (/= (car typ) (caddr typ))(PTE:s4 lst t) lst)
)
)
; Sub-function – 02
(defun LM:UnFormat ( str mtx / _Replace regex )
;; ⓒ Lee Mac 2010
(defun _Replace ( new old str )
(vlax-put-property regex ‘pattern old) (vlax-invoke regex ‘replace str new)
)
(setq regex (vlax-get-or-create-object “VBScript.RegExp”))
(mapcar
(function
(lambda ( x ) (vlax-put-property regex (car x) (cdr x)))
)
(list (cons ‘global actrue) (cons ‘ignorecase acfalse) (cons ‘multiline actrue))
)
(mapcar
(function
(lambda ( x ) (setq str (_Replace (car x) (cdr x) str)))
)
‘(
(“Д . “\\\\“)
(” ” . “\\P|\n|\t“)
(“$1” . “\\(\\[ACcFfHLlOopQTW])|\\[ACcFfHLlOopQTW][^\\;]*;|\\[ACcFfHLlOopQTW]”)
(“$1$2/$3” . “([^\\])\\S([^;]*)[/#\^]([^;]*);”)
(“$1$2” . “\\(\\S)|[\\](})|}”)
(“$1” . “[\\]({)|{“)
)
)
(setq str
(if mtx
(_Replace “\\” “Д (_Replace “\$1$2$3” “(\\[ACcFfHLlOoPpQSTW])|({)|(})” str))
(_Replace “\” “Д str)
)
)
(vlax-release-object regex)
str
)
;==================================================================================
; Main function
;==================================================================================
(ssget ‘((0 . “text,mtext”)))
(setq doc (vla-get-activedocument (vlax-get-acad-object))
objs (vlax-for o (vla-get-activeselectionset doc) (setq objs (cons o objs)))
tol (car (vl-sort (mapcar ‘vla-get-height objs) ‘<))
objs (PTE:sortobj objs “rdr” tol)
)
(or (setq excel(vlax-get-or-create-object “Excel.Application”))
(alert “Fail to Excel load”) (exit)
)
(vlax-invoke-method (vlax-get-property excel ‘Workbooks) ‘Add)
(vlax-put Excel ‘visible :vlax-true)
(setq cell (vlax-get-property (vlax-get-property excel ‘ActiveSheet) ‘Cells)
x 1 y 1
)
(foreach os objs
(foreach o os
(setq str
(if (= (vla-get-objectname o) “AcDbText”)
(vla-get-textstring o)
(LM:UnFormat (vla-get-textstring o) nil)
)
)
(vlax-put-property cell ‘item y x (strcat “‘” str))
(setq x (1+ x))
)
(setq y (1+ y) x 1)
)(princ)
)(vl-load-com)