Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Data extraction from tables to XLS

  1. #11
    All AUGI, all the time gfreddog's Avatar
    Join Date
    2003-07
    Location
    Pequannock NJ US of A
    Posts
    639

    Default Re: Data extraction from tables to XLS

    Quote Originally Posted by irneb View Post
    Yes , just type the following at the command prompt or in your lisp:
    Code:
    (TableExport nil "C:/MyData/Tables.CSV" "MyPrefix")
    Change the path & filename to the CSV as needed, and the "MyPrefix" can either be replaced with nil if you don't want a prefixed column, or to any other piece of text or a variable containing text.
    If I run this as is I can only select one table in the drawing to export. Using AutoCAD 2012 Vanilla.
    George V. Fournier Jr., CTS
    Sr. Sales Engineer - Autodesk Product Design Suite Premium 2014
    2006 AUGI DAWG (7th) - NJ AUGI Camp
    Volunteer Firefighter since 1985 & Bagpiper Wanna-be
    With the freedom of expression comes great responsibility


  2. #12
    All AUGI, all the time gfreddog's Avatar
    Join Date
    2003-07
    Location
    Pequannock NJ US of A
    Posts
    639

    Default Re: Data extraction from tables to XLS

    Quote Originally Posted by gfreddog View Post
    Ok I think that is what I really need but it might be lack of coffee or the head-cold I'm fighting off but how do I trigger this?
    If I try this as a LISP I get completely lost:

    (vl-load-com)

    ;TTBL - Export Tables to CSV file

    (DEFUN C:TTBL ()

    (TableExport nil "C:\Users\gfournier\Documents\AutoCAD Files/Tables.CSV" "MyPrefix")

    (defun ReadList (lst /)
    (cond
    ((= (type lst) 'Str) (ReadList (read (strcat "(" (vl-string-translate ",;" " " lst) ")"))))
    ((= (type lst) 'Sym) (eval lst))
    ((= (type lst) 'List) (mapcar (function ReadList) lst))
    (t lst)
    )
    )

    (defun SelectObjects (pt filter / ss n lst)
    (if pt
    (progn
    (setq pt (ReadList pt))
    (if (= (type pt) 'List)
    (cond
    ((and (>= (length pt) 2) (vl-every (function (lambda (i) (member (type i) '(Int Real)))) pt))
    (setq n (list (/ (getvar 'ViewSize) (* (getvar 'PickBox) 80.0)) 0.0)
    n (cons (car n) n)
    ss (ssget "C" (mapcar '- pt n) (mapcar '+ pt n) filter)
    )
    )
    ((vl-every (function
    (lambda (i)
    (and (= (type i) 'List) (vl-every (function (lambda (j) (member (type j) '(Int Real)))) i))
    )
    )
    pt
    )
    (cond
    ((= (length pt) 1) (setq lst (SelectObjects (car pt) filter)))
    ((= (length pt) 2) (setq ss (ssget "C" (car pt) (cadr pt) filter)))
    (t (setq ss (ssget "CP" pt filter)))
    )
    )
    )
    )
    )
    (setq ss (ssget "X" filter))
    )
    (if ss
    (progn (setq n (sslength ss)) (while (>= (setq n (1- n)) 0) (setq lst (cons (ssname ss n) lst))))
    )
    lst
    )

    (defun TableExport (pt fname prefix / lst eo f row col str)
    (if (and (setq lst (SelectObjects pt '((0 . "ACAD_TABLE"))))
    (setq f (open fname "a"))
    )
    (progn
    (foreach en lst
    (setq eo (vlax-ename->vla-object en)
    row -1
    )
    (while (< (setq row (1+ row)) (vla-get-Rows eo))
    (setq col -1
    str ""
    )
    (while (< (setq col (1+ col)) (vla-get-Columns eo))
    (setq str (strcat str ",\"" (vla-GetText eo row col) "\""))
    )
    (setq str (strcat ",\"" (vla-get-Handle eo) "\"" str "\n"))
    (if prefix
    (setq str (strcat ",\"" prefix "\"" str))
    )
    (princ (substr str 2) f)
    )
    )
    (close f)
    )
    )
    )
    George V. Fournier Jr., CTS
    Sr. Sales Engineer - Autodesk Product Design Suite Premium 2014
    2006 AUGI DAWG (7th) - NJ AUGI Camp
    Volunteer Firefighter since 1985 & Bagpiper Wanna-be
    With the freedom of expression comes great responsibility


  3. #13
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,344

    Default Re: Data extraction from tables to XLS

    Make sure that if you use backslashes in your path they get doubled. That's why I prefer using forward slashes instead.

    So your path should read as either one of these:
    Code:
    "C:/Users/gfournier/Documents/AutoCAD Files/Tables.CSV"
    "C:\\Users\\gfournier\\Documents\\AutoCAD Files\\Tables.CSV"
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  4. #14
    All AUGI, all the time gfreddog's Avatar
    Join Date
    2003-07
    Location
    Pequannock NJ US of A
    Posts
    639

    Default Re: Data extraction from tables to XLS

    Quote Originally Posted by irneb View Post
    Make sure that if you use backslashes in your path they get doubled. That's why I prefer using forward slashes instead.

    So your path should read as either one of these:
    Code:
    "C:/Users/gfournier/Documents/AutoCAD Files/Tables.CSV"
    "C:\\Users\\gfournier\\Documents\\AutoCAD Files\\Tables.CSV"
    This has sat to the side for awhile and I now have time/need to revisit...

    Is there a way to write the LISP so it prompts you for the file location each time?

    TIA
    George V. Fournier Jr., CTS
    Sr. Sales Engineer - Autodesk Product Design Suite Premium 2014
    2006 AUGI DAWG (7th) - NJ AUGI Camp
    Volunteer Firefighter since 1985 & Bagpiper Wanna-be
    With the freedom of expression comes great responsibility


  5. #15
    All AUGI, all the time gfreddog's Avatar
    Join Date
    2003-07
    Location
    Pequannock NJ US of A
    Posts
    639

    Default Re: Data extraction from tables to XLS

    Quote Originally Posted by gfreddog View Post
    This has sat to the side for awhile and I now have time/need to revisit...

    Is there a way to write the LISP so it prompts you for the file location each time?

    TIA
    I'm definitely having no luck
    George V. Fournier Jr., CTS
    Sr. Sales Engineer - Autodesk Product Design Suite Premium 2014
    2006 AUGI DAWG (7th) - NJ AUGI Camp
    Volunteer Firefighter since 1985 & Bagpiper Wanna-be
    With the freedom of expression comes great responsibility


  6. #16
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,344

    Default Re: Data extraction from tables to XLS

    Sorry, I must've missed this post. Try using the getfiled function. That shoul open a dialog so you can pic a filename. It returns the full path string or nil if the user cancels.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Data extraction
    By paulof in forum AutoLISP
    Replies: 0
    Last Post: 2011-11-29, 05:45 PM
  2. 2011: Data Extraction
    By ksmith.187551 in forum AutoCAD General
    Replies: 5
    Last Post: 2011-07-13, 02:10 PM
  3. UCS and Data Extraction
    By CADdancer in forum AutoCAD General
    Replies: 6
    Last Post: 2011-04-14, 09:53 AM
  4. Data Extraction
    By matt.wagner in forum AutoCAD LT - Wish List
    Replies: 7
    Last Post: 2009-04-27, 02:02 AM
  5. DB + multiple lookup tables + attribute extraction = headache!
    By bcalendine in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2007-12-06, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •