5

I have hundreds of DWG, AutoCAD files that I would like search and catalog into an MS Access Database.

Basically, I would like to search the DWG's and extract whatever description is in the Title box as well as the Date and bring everything over to Access making it a searchable catalog.

For example, I have a file name T-25682.DWG, which is titled Machine Spacer and created 01/20/2010.

I would extract that info form the DWG file and insert it into the Access database as such:

== ID ==    == DESCRIPTION ==    == CREATED ON ==    == FILENAME ==

    1       Machine Spacer       01/20/2010          T-25682.dwg

How can I approach and solve this problem? Is there an AutoCAD library I can use with Access? How can I search in a DWG file?

NGLN
  • 43,011
  • 8
  • 105
  • 200
AKKAweb
  • 3,795
  • 4
  • 33
  • 64
  • Apparently you can get [VBA modules for Autocad](http://usa.autodesk.com/adsk/servlet/ps/dl/item?siteID=123112&id=12900036&linkID=9240617) which should allow to automate, unless you wish to look at .Net – Fionnuala Sep 22 '11 at 17:02
  • That is more for allowing you to run VBA macros from within AutoCAD, from what I understand. I am solely looking into reading AutoCAD files using macros just like a simple .txt file. – AKKAweb Sep 22 '11 at 17:43
  • When I open the file with Word for example, everything in encoded with characters I cannot read. Is there a way to read what is in there or search for something and finding it – AKKAweb Sep 22 '11 at 17:52
  • The way I see it, is if you have the proper libraries, you can reference them in Access VBA and use that to read the relevant file properties, which include title, from the little googling I have done on the subject. – Fionnuala Sep 22 '11 at 17:59
  • In the same way that if you reference the Word library in Access, you can create a Word application object and work with all the properties and methods available through that. – Fionnuala Sep 22 '11 at 18:01
  • That is exactly what I wanted to do.... – AKKAweb Sep 23 '11 at 12:04

2 Answers2

3

I would avoid VBA altogether, AutoLISP can do the job for with far less pain. Here's how:

Create the "data extraction and writing to Access" functionality inside an AutoLISP file. The freely available ADOLisp library will make it a breeze writing to Access, if that fails, or you aren't able to do it you can always just write to a csv file...

Once you're able to do that for a single dwg file, create a script (using anything that can copy and open files, AutoLisp works too) to do the following:

  1. Copy that lisp file into a directory where your dwg files are, naming the file as acaddoc.lsp.
  2. Sequentially open every dwg in the directory. Upon opening, acaddoc.lsp will run and do its stuff.
  3. Delete acaddoc.lsp from that directory (else it will run every time you open a dwg in there).
  4. Repeat for every directory you have dwg files in which you wish to catalog.

Notes:

  1. Make sure that acaddoc.lsp closes the drawing when its done (or makes AutoCAD quit, depending on how you're opening the files).
  2. For this to work, your title blocks need to be reliable, make sure you add some error checking. You can use the script to log any issues to a text file as they find them...

AutoLisp is really really easy, for help with learning go to AutoLISP Beginners' Tutorials.

For the best place to ask questions and search for code snippets from previous answered questions, see Visual LISP, AutoLISP and General Customization.

NGLN
  • 43,011
  • 8
  • 105
  • 200
andyhasit
  • 14,137
  • 7
  • 49
  • 51
1

If you have a full version of AutoCAD you can try the Data Extraction Wizard. This works quite well for attributed blocks. If this is no good, the best places to try are the Swamp or the AutoCAD forums or AUGI.

VBA is deprecated in the last 3 versions of AutoCAD in favour of the .NET API, FYI

+edit+ Have a look at this (free) chapter on AutoCAD external database connectivity.

CAD bloke
  • 8,578
  • 7
  • 65
  • 114
  • Data Extraction Wizard, if it works, would be time consuming to get a huge library of files catalogued. From what I understand I would have to open one at a time and use that tool. I am not looking for anything within AutoCAD. I am looking for a way to use ACCESS/VBA to extract info from a DWG file. Thanks for your help! – AKKAweb Sep 23 '11 at 12:32
  • You can select a collection of files and save that collection, as well as the parameters of the extraction. You need AutoCAD or a version of the AutoCAD API to read the DWG files. They are a proprietary format and encrypted. Access has no native way to access (harhar) AutoCAD drawings. You would need to write an app based on AutoCAD REAL DWG or the ODA API, or buy an already existing app. Even with AutoCAD installed, any app that uses it must run inside the AutoCAD process - it is a limitation of that library. – CAD bloke Sep 25 '11 at 02:50
  • Actually, I'm not quite right there (ie, wrong) - ActiveX can run out of process. See http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS73099cc142f48755-5c83e7b1120018de8c0-2202.htm,topicNumber=d0e3474 Be warned - it is dog-slow and it is also in the process of being deprecated in favor of .NET. This might help: http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=3377116 – CAD bloke Sep 25 '11 at 03:00