Saturday, August 4, 2012

DXFert: Creating a DXF file in Excel

DXF files are a means of providing interoperability between AutoCAD and other programs.  AutoCAD can read and write *.dxf files and so can a number of other programs.  It is fairly straightforward to write a program which outputs a DXF file—provided you just want to draw something simple.  DXF files are a great option for auto-generating a bunch of drawings which can then be opened up in a CAD program and edited and saved in that program's native format.

I have written an Excel Add-In, DXFert (say, D-X-F-ert), in VBA which outputs a selection of points as either a 2D or 3D polyline.  It has been tested in 2010, but hopefully works in many earlier versions.  Here's how to install and use the add-in.

How to Install DXFert
  1. Download DXFert from my google shared document found here.
  2. Open Excel.
  3. Go to File → Options
  4. Select Add-Ins
  5. Click the Go... button beside Manage |Excel Add-Ins|.
  6. Click Browse... and navigate to the download location of the add-in and select the file (DXFert.xlam).
  7. Click the check box beside DXFert and click OK.
You should now see a DXF tab.

How to Use DXFert

Using DXFert is straightforward.  First you'll need to create two or three columns of numbers which represent the x, y, (and z) coordinates of the vertices of the would-be polyline.  Having so done:
  1. Optionally, pre-select the cells (headings, if any, not included) which contain the data you want to export as a polyline.
  2. Go to DXF → Export to DXF.
  3. In the dialog, select whether you want to export as 2D or 3D polyline.
  4. If you have not already selected the relevant cells, click the button beside the cell range input box and select the cells (when you have made your selection, you need to click the button on the right hand side of the window that came up for the cell reference selection to get back to the DXFert dialog).  Alternatively, type the cell reference.  You must choose a simple contiguous selection. I haven't added the smarts to the program to do anything more intelligent or convenient (so far anyway).
  5. Type a file name to save the exported file as or browse to a file name.  (NOTE:  DXFert is not careful about overwriting files so make sure you give your file a new name if you don't want to overwrite an existing file.)  It is in your interest (normally) to make sure you give the file a .dxf extension (which the Browse... option enforces).  
  6. Click Export.  The file will be created silently and the dialog will close.
How to View DXF Files

Several programs open DXF files including several AutoDesk programs (like AutoCAD) and some free viewers.  AutoDesk has their own free viewer program:  DWG TrueView.

No comments: