×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Creating AutoCAD DXF file by VB

Creating AutoCAD DXF file by VB

Creating AutoCAD DXF file by VB

(OP)
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

RE: Creating AutoCAD DXF file by VB

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.

RE: Creating AutoCAD DXF file by VB

I've done this in VB before.  You get _really_ good at text-proessing :)

Here is where I found out the DXF syntax.
http://usa.autodesk.com/adsk/servlet/item?id=752569&siteID=123112

I made functions for simple tasks, such as WriteCircle(Dim radius as Double, Dim x as Double, Dim y as Double, Dim layer as String) etc.

-Matt

RE: Creating AutoCAD DXF file by VB

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources