Link to home
Start Free TrialLog in
Avatar of CMPynn
CMPynn

asked on

How to Extract Drawing Attributes from AutoCAD into a Table in MS Access

What I'm trying to acheive is to be able to extract drawing attribute information from AutoCAD and then fill out the necessary fields in a form.

Is this possible.??

Another possible way would be to retreive similar information from a text file. For this to work though I would need to be able to select a drawing file from a directory and then have the code find the correct text file connected to that particular drawing. Then again place the info in a particular field of a form.

I would be glad of any help on this

thanks
Avatar of jobrienct
jobrienct

I could help you with the text manipulation if you can figure out where to retrieve the filenames from. embedded in the acad file ? try opening one in wordpad and searching for the filename. if they are always located in the same position in the file this is readily doable. If you can search for and find the path to the file and then retrieve the file after the path, its a bit more complex but still doable.

John
Avatar of CMPynn

ASKER

The text file stores the information in exactly the same manner for each drawing.

Is there a way to browse for a given file. I.e a .dwg file. Then based on that locate the associated txt file which will be stored in a sub folder below where the drawing is located and extract the information in to the table of the database.

thks
if we can match the filename, sure. vba can check for the exitence of the file, retrieve data from within the file from a specific point onward or search the file for that information and retrieve into variables, a recordset can then be opened and the variables stored to the table via the recordset.

you would need to provide me with the method to retrieve the startting point. the filename we need to read or the place to find the filename in the drawing file.

John
Avatar of CMPynn

ASKER

Not sure about that myself.

I know that you can "browse for a folder" and then use the information from there.

I was thinking there would be similar method for browsing for a file. ??

The way I imagined was that you locate a file name. That file name is then stored and the next part of the code looks for a txt file with the same name.

Then you get the extract from the text file and add to a new record.

Sounds good but how to do it not sure.

Does that explain any better.

apolgies

 
im saying do you know the filename and the path to it. if you do, tell me :)

now dont just say "yes", give me the path and filename to the file, nad the contents of that file so i can tell you how to extract the information you need.

John
Avatar of CMPynn

ASKER

the file would be called say "00001.txt"

and it would be located in a folder "C:\drawings\info"
what would be in the file ?

John
Avatar of CMPynn

ASKER

a list of attributes
e.g.

drgnumber    0001
title1             test
title2             of
title3             vba
rev                A


etc. This is dependant on what attributes you were to create in the block. But that is a general idea.
looks simple enough. ok im writing a parser.

always the same number of lines in the file?
fieldnames always the same?

Im writing some air code to parse it.

John

ASKER CERTIFIED SOLUTION
Avatar of jobrienct
jobrienct

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
my experience with autocad (I wrote a BOM app) pointed out the fact that you can specify that AutoCad create an extract file in CSV format and you can supply a template file with the names of the attributes to extract. With your file in CSV format you can link directly in Access and then run an append query without the need for parsing code.

Steve
yes you can. CSV is not what you showed me however :)

CSV format

myfile.CSV
---------------------------------
partnum, description, width, heght
           1, small armature, .10, 1.6
           2, large armature, .25, 2.5

if you can get that format exported you can use file-> get external data -> Import

select text files and then select your file. a wizard will walk you through the settings.

John



John, I think you read my post as comming from the original questioner.

Steve
ouch, and so i did Steve :)

Do you recall the procedure to export it?

John
Avatar of CMPynn

ASKER

Ok guys, I really appreciate your help here but there seems to be more than one way to do this.

Firstly to touch on CSV export from AutoCAD. This is fine but means that you have to do that manually for each drawing. This defeats the object. As it would be no different from typing the information into the database.

Onto your method John. I forgot to mention that at the start of the text file is a description of the software creation etc which is not relevant to the attributes that I would like to extract. This is items such as the date and time the file was saved etc. The attributes that I require start at line 11 through line 30. If that helps narrow it down. I'm understanding this a bit more.

One idea I found was creating comand using the transfer text command.
With a width-spaced text file you have to create a specification but using the wizrd I could not figure out what the necessary changes were in order for this to work. Would this be a better solution.

What about the GetOBject or CreateObject route going directly to AUtoCAD. ??

thks

Avatar of CMPynn

ASKER

Another point I have realised.

Is that the name of the attributes don't exactly match the table. Can this be got around.

E.G

The attributes read

BASENAME 0001.dwg
DWGDIR \\LOCAL:C:\
TBHANDLE    2B9
DWGTITLE1   General Arrangement Showing
DWGTITLE2   Indicative Structure for
DWGTITLE3   Travelator Bridges
DWGTITLE4  
JOBTITLE1   A Test
JOBTITLE2  
JOBTITLE3  
JOBTITLE4  
DWGSTATUS   Concept
JOBNUMBER   111111
JOBSUFFIX  
TBSCALE     1:200
ORIGINATOR  
ISSUEDATE  
REVISION    1
DWGNUMBER   S/SK05
DESCRIPTION

Where as my table reads

DrawingNumber
DrawingTitle1
DrawingTitle2
DrawingTitle3
Revision
DScale
Status
CADFilename
path

Hope this makes more sense.

thanks
ok so you can decide what is important and ignore the rest or you can create a table to support the file format.

Please post the *entire* contents of of least 2 of your dwg files so that we can determine the common elements of the layout. The code above can be modified to test for start/end locations of the relevent data and then split into an array and then the pertinet elements extracted based on either location in the array or exact string matching on the field names in column 0 of the array.

John
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
also please post your field names from the table with a matching column for fieldnames from the dwg file that would contain those values. ie:

DrawingNumber  DWGNUMBER
DrawingTitle1 DWGTITLE1  
DrawingTitle2 DWGTITLE2  
DrawingTitle3 DWGTITLE3  
Revision REVISION
DScale TBSCALE    
Status DWGSTATUS  
CADFilename BASENAME
path DWGDIR

or simply confirm that i've got it right. Also confirm that these values exist in every dwg file. looks they should but they could be null - which is fine, as long as we know they wont disappear from the file because they are null.

John
Avatar of CMPynn

ASKER

John,

In your last post you have go the relationship between the table and data contained within the txt file correct.

The information would be contained in every txt file. I.E.

# This file was automatically generated by ARX Module
# written at: 03 November 2003 10:59:23
# sActualName = C:\rebar schedule.dwg

DATA_FORMAT 1.0
GENERATOR ARX

START GENERAL

# Basic info about drawing
BASENAME rebar schedule.dwg
DWGDIR \\LOCAL:C:\
TBHANDLE    C4A66
DWGTITLE1   Typical Beam Details
DWGTITLE2  
DWGTITLE3  
DWGTITLE4  
JOBTITLE1  
JOBTITLE2  
JOBTITLE3  
JOBTITLE4  
DWGSTATUS  
JOBNUMBER  
JOBSUFFIX  
TBSCALE    
ORIGINATOR  
ISSUEDATE  
REVISION    
DWGNUMBER  
DESCRIPTION

END GENERAL

and then another example

# This file was automatically generated by ARX Module
# written at: 03 November 2003 10:58:49
# sActualName = C:\rebar colschedule.dwg

DATA_FORMAT 1.0
GENERATOR ARX

START GENERAL

# Basic info about drawing
BASENAME rebar colschedule.dwg
DWGDIR \\LOCAL:C:\
TBHANDLE    F191
DWGTITLE1   Column Details
DWGTITLE2  
DWGTITLE3  
DWGTITLE4  
JOBTITLE1  
JOBTITLE2  
JOBTITLE3  
JOBTITLE4  
DWGSTATUS  
JOBNUMBER  
JOBSUFFIX  
TBSCALE    
ORIGINATOR  
ISSUEDATE  
REVISION    
DWGNUMBER  
DESCRIPTION

END GENERAL

As you can see that it is not necessary that all the entries have data from the attribute. So they could be null but the general format will always be the same.

thks
Avatar of jadedata
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: jobrienct {http:#9972285} & stevbe {http:#9984467}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jadedata
EE Cleanup Volunteer