Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating AutoCAD DXF file by VB

Status
Not open for further replies.

shakildor

Civil/Environmental
Jun 19, 2003
35
Hi !!!!
Can anyone please tell me how to create AutoCAd compatible DXF files from Visual Basic
(sorry ...it might be a many time discussed old problem)

Shakildor
 
Replies continue below

Recommended for you

A dxf file is a pure ASCII text file. I build the dxf file as a text variable DXFText, then write it to disk. The first four lines are always:

DXFText = 0 & vbCrLf
DXFText = DXFText & "SECTION" & vbCrLf
DXFText = DXFText & 2 & vbCrLf
DXFText = DXFText & "ENTITIES" & vbCrLf

The last four lines are always:

DXFText = DXFText & 0 & vbCrLf
DXFText = DXFText & "ENDSEC" & vbCrLf
DXFText = DXFText & 0 & vbCrLf
DXFText = DXFText & "EOF" & vbCrLf

When DXFText is complete, create a text file and print to it like:

Open "C:\" & FileName.Text & ".Dxf" For Output As #1
Print #1, DXFText
Close #1

You need to know the group codes for AutoCAD. For instance, to do a circle, it's:

DXFText = DXFText & 0 & vbCrLf
DXFText = DXFText & "CIRCLE" & vbCrLf
DXFText = DXFText & 8 & vbCrLf
DXFText = DXFText & Layer$ & vbCrLf
DXFText = DXFText & 10 & vbCrLf
DXFText = DXFText & Round(CenterX, 4) & vbCrLf
DXFText = DXFText & 20 & vbCrLf
DXFText = DXFText & Round(CenterY, 4) & vbCrLf
DXFText = DXFText & 40 & vbCrLf
DXFText = DXFText & Round(Radius, 4) & vbCrLf

In this case, 8 preceeds the layer name, 10 preceeds the x coordinate of the circle's center, 20 preceeds the y coordinate of the circle's center and 40 preceeds the circle's redius.

Each AutoCAD entity has similar "codes" that identify it's geometric description. Find them in AutoCAD help or a book. YOu can also lear a lot by creating a dxf file in AutoCAD and reading it.
 
I have also created dxf files from VB5. In my case I created a .bas module that contained all the dxf 'bits' I needed and called them as required.

A similar approach can be used with PHP on a web site so you can take user input and send them a dxf drawing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor