Author Topic: Export text to Excel  (Read 5341 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Export text to Excel
« on: August 25, 2010, 04:41:09 PM »
I thought there was a thread (or two) about exporting text to Excel and based on the coordinates of the text it would put it in different cells rather than one tall column.  I found a few threads but they used VBA.  :\
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Export text to Excel
« Reply #1 on: August 25, 2010, 04:59:20 PM »
Here is an old one I have that I think will do what you want.  Not sure though, as I haven't used it in awhile.

Code: [Select]
(defun c:ExportTextTable (/ tempPt XValList PtValList tempList tempStr EndList XValCnt StrCnt MaxCnt StrList Opened *error*)
   
    (defun *error* (msg)
   
        (if Opened (close Opened))
        (if msg (prompt (strcat "\n Error-> " msg)))
    )
    ;--------------------------------------------------------------
    (if (ssget '((0 . "TEXT")))
        (vlax-for obj (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-Acad-Object)))
            (setq tempPt
                (vlax-get
                    obj
                    (if (equal (vla-get-Alignment obj) 0)
                        'InsertionPoint
                        'TextAlignmentPoint
                    )
                )
            )
            (if (not (vl-position T (mapcar '(lambda (x) (equal (car tempPt) x 0.00001)) XValList)))
                (setq XValList (cons (car tempPt) XValList))
            )
            (setq PtValList
                (cons
                    (cons
                        (vl-string-translate "," ";" (vla-get-TextString obj))
                        tempPt
                    )
                    PtValList
                )
            )
        )
    )
    (foreach lst PtValList
        (if (setq tempList (assoc (setq tempStr (rtos (caddr lst) 2 10)) EndList))
            (setq EndList
                (subst
                    (list
                        tempStr
                        (cons lst (cadr tempList))
                    )
                    tempList
                    EndList
                )
            )
            (setq EndList (cons (list tempStr (list lst)) EndList))
        )
    )
    (if EndList
        (progn
            (setq EndList
                (vl-sort
                    EndList
                    '(lambda (a b)
                        (> (distof (car a)) (distof (car b)))
                    )
                )
            )
            (setq XValList (vl-sort XValList '<))
            (foreach lst EndList
                (setq lst
                    (vl-sort
                        (cadr lst)
                        '(lambda (a b)
                            (< (cadr a) (cadr b))
                        )
                    )
                )
                (setq XValCnt 0)
                (setq StrCnt 0)
                (setq MaxCnt (length XValList))
                (setq tempStr "")
                (repeat (length lst)
                    (while (not (equal (cadr (nth StrCnt lst)) (nth XValCnt XValList) 0.0000001))
                        (setq tempStr (strcat tempStr ","))
                        (setq XValCnt (1+ XValCnt))
                    )
                    (setq tempStr (strcat tempStr (car (nth StrCnt lst))))
                    (if (< StrCnt MaxCnt)
                        (setq tempStr (strcat tempStr ","))
                    )
                    (setq StrCnt (1+ StrCnt))
                    (setq XValCnt (1+ XValCnt))
                )
                (setq StrList (cons tempStr StrList))
            )
            (setq Opened (open "c:/test/ExportedText.csv" "a"))
            (foreach str (reverse StrList)
                (write-line str Opened)
            )
        )
    )
    (*error* nil)
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Export text to Excel
« Reply #2 on: August 26, 2010, 08:09:26 AM »
I'll have a look.  Thanks!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

fixo

  • Guest