Search:

# MS Office Forum

Asked By: Bailey    Date: Mar 09    Category: MS Office    Views: 5837

I have been asked to acquire data from Autcad files and have not the
foggiest idea of how to go about getting it.

I am told that these files all contain the same table and that tjis
table contains the same fields in all files.

I need to somehow get the field data from these files. Is there anyone

Share:

Do a Google search using this search criteria ... extract data  from autocad
files
Several options came up

What's the extension of the file you have been asked  to get data  from?

The files  are all .dwg files (standard AutoCAD). The block I will
need to extract the informatioon from has about 30 different fields,
but I only need 8 of them. I would be happy to stip them all into
excel, then I could use the ones I need and get rid of the rest
easily. My problem is importing the data  from AutoCAD.

My understanding is that Autocad has been using VBA for some time now. Maybe
that's a way to get the info you want.
Assuming you run autocad, try hitting Alt F11 or going throught the menus to
see if you can get to the VBE... And then use the help.

Unfortunately I don't use autocad any more so I can't really help. If
however it's possible to create a .DXF file and *if* that contains the
information you need then we can revisit because that's only a text file.

I have used AutoCAD sometimes. Try to use the foollowing:

Step 1 select "create new data  extraction"

step 2 data source select Drawing/sheet or select object in the
curring drawing

Step 3 you will see all the blocks in the current drawing, selecte
the one you need

Step 4 you will see all the entities/properties you want/need

step 5 you will see all the block you selected and its entities data,
in a table, you can make some task there.

step 6 you can select between put all the data in a table  in the
current drawing or exporting it all to external file, e.g. excel!!!
xls!!! txt, cvs, etc, i recomend you to select xls, give the name a
then click next

Step 7... there is nothing to do here

Step 8... click in finish

When you get your xls file, you can manage you information as you
want... Good luck!!!! (Sorry by my english, I'm from Argentina)

PS: in AutoCAD 2006/2007, it tool is called Attribute extraction, it

That's great info!! Thankyou!!!!!!!!!!!!!!

While this might work, it is almost what I am having to do now to
get the data  I need. The problem is that this process takes a long
time for each drawing, even getting faster only makes it slightly
shorter duration.

Today I have 653 drawings I have to do this to, and that will take
me a good portion of my day. I am looking for a way to automate this
so that the computer can do it and leave me out of it. Then once the
excel sheet is built I can run other macros/vba programs to
edit/modify/analyze the data. The excel macros are already built....
I'm a lazy engineer, I hate doing stuff like this, so I find ways to
not have to.

http://www.tek-tips.com/faqs.cfm?fid=5800

code.filehungry.com/.../visual_ba

www.experts-exchange.com/.../Q_
21390226.html
Some code at the bottom of this.

en.allexperts.com/.../right-approach.htm

I got all of these by googling autocad dwg vba.

I think ADO is probably the way for you to go.

.... And this one is from an AUTODESK discussion group with code.

Note that a lot of this is to use VBA *from autocad* to push pull
information to different applications rather than to use the applications
VBA to pull from the DWG file.

And I'm sure that there is autocad vba code out there to go through a set of
DWG files.

One final thing... I have no idea  if there is a "macro recording" facility
in autocad vba but if there is that should help as well.

there is a macro recording utility in AutoCAD, i havent't tried it,
perhaps it works...

Let a couple of hours...

I actually taught a college class many years ago, but lots has changed since
then and I have not kept up... (It was before WINDOWS!!!)
The autocad files  have a .dwg extension.
Autocad used to use a programming language derived from the LISP language.
Because they are a CAD application, they had MANY custom functions, they called
their version AutoLISP. I even wrote some extraction programs using AutoLISP
back in the '80s.
Since then, they jumped on the band-wagon and began using Objects, Visual Basic,
they also now have a data  Extraction Wizard that is designed specifically to
Unfortunately, I think Tim needs to find an AutoCAD user group and address his
question there.
the problem is to get the AutoCAD data out where Excel can get to it.
I found several places that showed how to use AutoCAD's Extraction Wizard, but
that works great on one file, or even two. I think I could spend a weekend and
maybe get 50 or 100... but
if Tim works in a an environment where the number of files is large (I have
140,000) then
he needs to automate the process, which means he needs an AutoCAD expert...
Once he gets the data, out of AutoCAD, THEN I think we can do LOTS to help him
manipulate the data. But the .dwg format is not a format that we can get to

This is an accurate description. The files  are suffixed dwg (Autocad
standard). While there are not many files that must be searched at
any given time, the total number of drawings that will be searched
will easily reach into the hundreds of thousands by the end of the
year. I am trying to make my life easier by having excel do the
tedious work for me.

I have written a few things in LISP (Lost In Stupid Parentheses),
but frankly I would rather revert to binary coding than have to
relearn that nonsense.

I understand from other I have spoken with that the new versions of
AutoCAD include VBA which could make my life easier, but I was
hoping maybe someone had already tackled this dragon or maybe one of
his cousins and could give some guidance.

My personal opinion is that "lazy" engineers are the best engineers.
They tend to look for ways to make work easier for themselves and others!
I think you need to look at the macro programming available in Autocad.
You may need to find a dicussion forum specifically for that.
Excel can launch the Autocad application and open the file, but the
methodology, syntax and techniques for getting to the data  in the tables
Once you determine how THAT is done, you can use the add-ins for Excel
to get to the data.
I think it's VERY possible to automate this task.
But, like I said, you're going to have to look to AutoCAD to find
the techniques to get at it.
Once you've got that figured out, you can extract the data from all the files
and even set up a scheduled task to refresh the data from any files  that have
been modified since the last time a refresh was done.

looking for an answer. You don't seem to want to use
the built-in AutoCAD exporter, so it seems you really
only have one avenue left.. to extract from the .dwg
file yourself using VBA.

Have you ever opened a .dwg file using, say, Notepad?
(BTW, I'm familiar with AutoCAD and Lisp, but not since
The .dwg file is undoubtedly a huge text file, albeit
possibly with many non-printable characters.

My question is -- is the file understandable? Can you
see the data  you are looking for? I assume it is something
like a list of room, with dimensions -- or something of
that ilk. If so, you could create a "parser" using VBA.
Just create a loop to read the file line by line.. skip
over lines that are not of interest; parse the ones that
are.

disagree with "you really only have one avenue left".
scenario:
I have an Excel file that reports data  that is stored in 12,000
MSWord documents.
The Excel VBA creates a list of files  and opens each one in turn.
Then, the Excel VBA utilizes the functions available in Word VBA
to extract the data and store it in an Excel sheet.
A similar technique could be used here.
I believe that AutoCAD utilizes VBA.
Tim needs to look into the ACad VBA functions necessary to
extract the data from the ACad tables.
Then, place these commands into the Excel VBA.
It CAN be done, but I don't have AutoCAD available so that I can test it.

Try to save dwg file as a dxf ascii file. In dxf ascii file you will
see all the blocks and it attributes as in a txt file opened in

From this file perhaps you can get all you info using excel.

Acad doesn't have a macro recording utility, but has vba.

Well, if I do that I will need to write a second program to resave
the files  with that extension..... Manually doing that alone would
take days. There are many thousands of files I have to do this for.

This question will show you just how little I know this language. If
my program is run under he auspices of Excel and opens AutoCAD, can
the Excel VBA call commands that may only be available in AutoCAD
VBA?

It does help some. I am trying to open the dwg in autocad using excel vba. I
think from there I can use vba to run a script file that would export the data
from excel to a separate temporary file that can be read using vba. Part of my
problem is that I am much better in C++ than anything else. My vba experience is
limited, so I am stumblebumming along. Right now I can't even get autocad to
open cia vba. I simply do not know the right command sequences and the
auto-comlpete thing in there doesn't help much because, like I said, I simply do
not understand the commands. I'm still pretty new to vba. However, this has
helped me cement in my mind what I need to do in order to accomplish this feat.
If you believe there is an easier way than the one I have described, please,
post it and I'll alter my pathway. Thanks for your help.

I worship C++ programers, and consider VB (me)
programmers an inferior bunch. Nonetheless, maybe the
following VB / VBA code will get you started. It is
intended as a generic sketch to cover various issues you
may encounter.

02.. targt = "c:\temp\text.txt"
03.. Close #1
04.. Close #2
05.. Open fpath For Input As #1
06.. Open targt For Output As #2
07.. For jj = 1 to 100
08..... Line Input #1, txt
09..... extr = Left(txt, 4)
10..... If extr = "ROOM" Then
11........ Write #2, txt
12..... End If
13.. Next jj
14.. Close #1
15.. Close #2

OK, what have I done here??

Line 1 sets the source file name (with full path
specified). In the example, it is hardwired. You could
certainly set them from an array inside of a higher level
loop that populated the array with all file names of
interest.

Line 2 sets the target file name. Here, I am using
the simplifying approach of just writing to a text
file. You could enhance this by writing directly to
Excel.

Lines 3 and 4 merely close file pointers (good practice,
as during debugging, if the file is still open, you'll
get an error).

Lines 5 and 6 open the respective files  and associate
a file pointer to each.

Line 7 is a simple For .. Next construct to get you
through the source file, line by line. Many enhancements
possible here -- I'm just trying to sketch the general flow.
But, yes, as written, the loop would only interate 100
times.

Line 8 reads the a line of the source file (up to CrLF -
carriage return + line feed), and puts the results in
the variable txt. Random length lines should be handled
by this approach, assuming there is always a CrLF at the
end of each line).

Line 9 extracts the left-most 4 characters, and assigns
them to the variable extr. This is in anticipation of
you needing to skip over a block of lines in the source
file until some particular point of interest is reached.
Natch, modify to meet your needs.

Line 10 tests to see of the desired block has been
reached.

Line 11 is where the extracted line of text is written
to your target file (and/or Excel).

The rest should be pretty self explanatory. A minor
disclaimer --- the foregoing code is VB. I'm pretty sure
the same statements are available in VBA.

Let me know if you need me to expand on any of the
foregoing.

I follow your code, and I have created many delimited excel files
this way, and to be honest, perhaps to my own shame, I have never
tried to open a .dwg file using anything but AutoCAD.... I know what
to do from there if I can find the text.... The problem I might run
into with this method is that the text is contained in a block in
AutoCAD, but I might be able to rip the text after the block field
titles.... I'll see what happens.... Thanks.

Good luck!! If, however, the file is encrypted , then we may be sunk ...

the problem STILL is the automatic generation of thousands
of file exports, or in this case, DXF files!
If Tim was willing to take the time to save the file as DXF, then
he might as well go ahead and export the table  as a link to excel!
According to this site:
macros.

the problem here is that you're assuming that a .dwg file is an ASCII file.
It is not.
Therefore, when you try to read in a "line" from the file, there will be only
one line
(since there are no CRLF characters)
and it will look something like:
Û8Š·ÏArQ< ÑãpcB*€x"&D[?7Õ3 DØÀ@ …—!p
which is not something I would like to repeat in public.
Tim still needs to figure out how to launch the AutoCAD application and have VBA
interrogate the table  data.
Using the Shell command, I think you can launch autocad with a filename as a
command line option.
but you still have to find the VBA coding to get the file export.
You MIGHT be able to use a combination of Shell, AppActivate, and SendKeys to
send the keystrokes necessary to export the table.
But I don't think you're going to get around the need to launch the AutoCAD
application.

Haha.. good thing I added that qualifier "assuming there
is a CrLF at the end of each line." Thanks for that info --
I did not know that there are none.

However, I would offer that all is not lost. I have worked
with huge text files  that consist of a single "line". So,
perhaps Tim could modify my code frag to simply parse the
solo line -- which could be 500,000 characters long or more.
I think the same general logic would apply.

Thus, the "Line Input" statement would be moved outside of
the loop, and instead, a Mid function would be used inside
of the loop to examine said line character-by-character.

Skipping over non-printable characters is a piece of cake --
he could still use my simplistic If..EndIf branch to skip over
"junk" until he gets to the desired section of the "line".

I think you're still missing the point.
The entire FILE is non-printable characters!
The file is not a "document" as much as it is a "drawing".
the definition of lines, arcs, circles, dimensions include
arrowhead type, size, extension length, all sorts of GRAPHICAL data.
It just so happens that within the graphical context, we insert
some text. AutoCAD doesn't save the text in one way, but encrypt
everything else.. it encrypts it all.
I opened an autocad DWG file in a text editor.. there is not a single
recognizable word in the whole file.
The fact is that the file is NOT ASCII.. therefore, opening it as if it WERE
an ASCII file won't do any good.
Ever tried opening a .jpg file with a text editor?
Try it... you KNOW that somewhere in the file is a word.. but you won't find
it in the text editor!!!

Yes, I can appreciate that the majority of the data
is graphical in nature, as you describe. However,
extract a block of data  from a number of files. I
made the assumption that there is some common "label"
that identifies beginning of the desired block, and
further that it was a text-based "label" -- I assume
that it is possible to enter a "note" to appear on an
AutoCAD drawing that is in recognizable text.

But, hey, I'm just trying to be helpful. I'll wait
to hear from Tim.

i tried to save a dwg file as dxf ascii format file, and you will see all
the gaphical data  as ascii text as follows:

0
SECTION
2
9
$ACADVER 1 AC1015 9$ACADMAINTVER
70
6
9
$DWGCODEPAGE 3 ANSI_1252 9$INSBASE
10
0.0
20
0.0
30
0.0
9
$EXTMIN 10 283.4756482805541 20 114.5337074898808 30 -0.0015258207003583 9$EXTMAX

some stuff.

This is the drawing.dwg file saved as a drawing1.dxf. So, you can make a code
that:

1.- save the file as dxf ascii format (notice that the file can be saved as dxf
binary format)
2.- Read the attriobutes of selected blocks
3.- send that attributes to excel.
4.- manage that info as you want.

I'm beginning at vba and autocad, so, it's a little help. I hope it would be
useful

Hi All,
I found here some discussion regarding Auto Cad, If you want more discussing & better solution, visit to the below link:
http://www.designpresentation.com/
http://www.formatconversion.biz/
It will be more easy to contact them and send your problem details to get solution online.

Didn't find what you were looking for? Find more on AutoCAD Table Data Extraction Or get search suggestion and latest updates.