+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Super Member Bill Tillman's Avatar
    Using
    AutoCAD 2013
    Join Date
    Oct 2008
    Location
    Miami, FL
    Posts
    874

    Default Excel File Troubles

    Registered forum members do not see this ad.

    I am trying to become an expert on interfacing between Excel and AutoCAD in a relatively short period of time. So for now I am stumbling through many of these issues. This morning I found what seems to be a nice collection of LISP code which can work with Excel files, it's called GetExcel.lsp. I've learned a lot by studying the code so far but there are some problems I can't seem to figure. First off, the dreaded (vl-load-com) issue. It was puzzling to me why developers leave this out of the code until I read Lee Macs insightful posting about ACADDOC.lsp.

    I have a very simple spreadsheet with values in only 3 cells. When I call the GetExcel part of the code I keep getting this message:

    ; error: Automation Error. Excel cannot access 'Template'. The document may be
    read-only or encrypted.

    The file in question is neither open by anyone else, nor is it set to R/O. I can post the code I'm using but it's rather lengthy and is available at this URL:

    http://web2.iadfw.net/terrycad/LISP/GetExcel.lsp

    My goal is to learn how to open any Excel file, read in the required data, and then be able to create a quick drawing based on the values being dimensions. I think I can handle that part if I can just find a way to get the data from Excel into my AutoCAD file.

    Thanks again and I appreciate everyone's patience. I realize this is brutal explaining to a novice from experienced programmers here at this forum.
    It's deja vu, all over again.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,744

    Default

    Hi Bill,

    You've set yourself quite a challenge! In the past I've written quite a few applications which interface with Excel, some freeware, some not, but in my opinion, one of the most difficult parts about working with Excel is the size of the Excel API coupled with the layout of the MSDN documentation which can be like navigating through a maze at times.

    Here are some examples from theSwamp which may help you towards your goal:

    http://www.theswamp.org/index.php?topic=31441.0
    http://www.theswamp.org/index.php?topic=10101.0
    http://www.theswamp.org/index.php?topic=35157.0
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,744

    Default

    Here is the MSDN Documentation:

    Excel Object Model Reference
    Excel Object Model Map
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  4. #4
    Super Member Bill Tillman's Avatar
    Using
    AutoCAD 2013
    Join Date
    Oct 2008
    Location
    Miami, FL
    Posts
    874

    Default

    Thanks alot. I'm in a real pickle in that I've been out of work for the last few months and need a job badly. A local firm has asked me to assist and if I can prove that at least I can get the basics done, I might land a long term project with them. They want to interface between Exel and AutoCAD. My programming skills aren't the best but their improving everyday so here's to catching this train.
    It's deja vu, all over again.

  5. #5
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,952

    Default

    Good luck, Bill!
    "Potential has a shelf life." - Margaret Atwood

  6. #6
    Super Member Bill Tillman's Avatar
    Using
    AutoCAD 2013
    Join Date
    Oct 2008
    Location
    Miami, FL
    Posts
    874

    Default

    It's starting to gel for me. I have gotten the GetExcel code to return the list *ExcelData@ and it contains this:

    (("1" "2" "3")) which is something like what I expected because cells A1, B1 and C1 contain the values 1,2 and 3 respectively. I was having a brain fart earlier and got that part wrong.

    So I want to parse this now and isolate the three items in this list so I can assign them to variables. In my haste I tried:

    (setq pt1 (car *ExcelData@))

    which I am assuming will return "1" or just 1 as its the first item in the list. But instead pt1 ends up being ("1" "2" "3") with only one set of the paranthesis being removed.

    Okay I'm seeing the light now. If I ask for (car *ExcelData@) I will get the list with the outside parens removed because that's actually the first item in the list. Then I ask for (car pt1) and I get "1"....hooray, but how can I get rid of the quotes? Or is it necessary to convert this to a number as I plan on using these values as dimensons eventually to draw some simple shapes like rectangles and lines, etc..
    It's deja vu, all over again.

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,744

    Default

    Code:
    (mapcar 'atof (car *ExcelData@))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  8. #8
    Super Member Bill Tillman's Avatar
    Using
    AutoCAD 2013
    Join Date
    Oct 2008
    Location
    Miami, FL
    Posts
    874

    Default

    Code:
    (setq pt1 (mapcar 'atof (car *ExcelData@)))
      (setq pt2 (car pt1))
      (setq pt3 (cadr pt1))
      (setq pt4 (caddr pt1))
    This gets me where I wanted to be today. The three values now assigned to something I can work with in AutoCAD and do some drawings. Now I'm dangerous. As they say, I now know enough to really screw things up....!

    Today, a simple spreadsheet....Tomorrow, the World!
    It's deja vu, all over again.

  9. #9
    Super Member ScribbleJ's Avatar
    Computer Details
    ScribbleJ's Computer Details
    Operating System:
    Windows 7
    Computer:
    Dell Precision T3500
    CPU:
    Intel(R) Xeon(R) CPU W3530 @ 2.8GHz 2800 Mhz
    RAM:
    12 gig
    Graphics:
    Nvidia Quadro 600
    Primary Storage:
    237 GB
    Monitor:
    Main: Dell 2408 Aux: Dell 1703FP
    Discipline
    Civil
    ScribbleJ's Discipline Details
    Occupation
    Civil Design Tech for Water / Waste Water Industry.
    Discipline
    Civil
    Details
    Roadway designs, water and waste-water treatment systems and water distribution systems.
    Using
    Civil 3D 2011
    Join Date
    Dec 2008
    Location
    Rancho Cordova, CA
    Posts
    539

    Default

    Bill do you happen to have AutoCad Map 3D? If so the task at hand can be much easier. I will leave it at that until you reply other than Map 3D has the same functionality as ArcGIS software does in respect to database files (i.e. converted Excel files). Once you get your data into Map 3D you can make thematic maps with it.
    Calvin
    Soli Deo Gloria

  10. #10
    Super Member Bill Tillman's Avatar
    Using
    AutoCAD 2013
    Join Date
    Oct 2008
    Location
    Miami, FL
    Posts
    874

    Default

    Registered forum members do not see this ad.

    No, I'm not using 3D Civil, I more of an architectural/structural user. So plain vanilla AutoCAD is what I have to work with.

    I had so many distractions today but was able to get back and play around some more with the GetExcel.lsp program. Turns out there is another module in it called GetCell which does the parsing of the data as well and you can simply ask for it to:

    Code:
    (setq pt6 (GetCell "C1"))
    and it will give you the value in cell "C1". Still, I'm learning alot more about how to interface between Excel and AutoCAD. Each day I know 100% more than I did yesterday.
    It's deja vu, all over again.

Similar Threads

  1. import excel file
    By silviu30 in forum AutoCAD General
    Replies: 12
    Last Post: 8th Aug 2010, 12:35 pm
  2. Excel File In R14
    By gsksun4 in forum AutoCAD Beginners' Area
    Replies: 0
    Last Post: 27th Jan 2010, 03:15 pm
  3. Insert Excel file to Cad
    By BEKA in forum AutoCAD Drawing Management & Output
    Replies: 9
    Last Post: 9th Jan 2010, 05:37 pm
  4. EMAILING DWG FILE AND LOSEING EXCEL FILE
    By J-LYLE in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 6th Jun 2006, 10:09 pm
  5. Referencing an Excel File
    By WwhawkwW in forum AutoCAD General
    Replies: 1
    Last Post: 2nd Nov 2005, 09:50 am

Bookmarks

Posting Permissions

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