Export to Other File Formats
 
 
 

If you need to use an AutoCAD drawing in another application, you can convert it to a specific format by using the Export method. This method exports the AutoCAD drawing to a WMF, SAT, EPS, DXF, or BMP format. The Export method takes three values as input: the name for the new file to be created, the extension for the new file, and the selection set of objects to export.

When exporting to WMF, SAT, or BMP format, you must provide a nonempty selection set. This selection set specifies the objects from the drawing to export. If no selection set is specified, nothing is exported and a trappable invalid argument error results.

When exporting to EPS and DXF formats, Export ignores the selection set argument, but it is still required. The entire drawing is automatically exported for these formats.

Export a drawing as a DXF file and import it again

This example creates a circle in the current drawing. It then exports the drawing to a file called DXFExprt.DXF, opens a new drawing, and imports the file. Note that an empty selection set is provided as an argument to Export. The Export method ignores selection set information when exporting a DXF file, but a syntax error results if the argument is omitted.

Sub Ch3_ImportingAndExporting()


	' Create the circle for visual representation
	Dim circleObj As AcadCircle
	Dim centerPt(0 To 2) As Double
	Dim radius As Double
	centerPt(0) = 2: centerPt(1) = 2: centerPt(2) = 0
	radius = 1
	Set circleObj = ThisDrawing.ModelSpace.AddCircle _
					(centerPt, radius)
	ThisDrawing.Application.ZoomAll


	' Create an empty selection set
	Dim sset As AcadSelectionSet
	Set sset = ThisDrawing.SelectionSets.Add("NEWSSET")


	'Export the current drawing to a DXF file in the
	' AutoCAD temporary file directory
	Dim tempPath As String
	Dim exportFile As String
	Const dxfname As String = "DXFExprt"
	tempPath = _
	 ThisDrawing.Application.preferences.Files.TempFilePath
	exportFile = tempPath & dxfname
	ThisDrawing.Export exportFile, "DXF", sset 


	' Delete the empty selection set
	ThisDrawing.SelectionSets.Item("NEWSSET").Delete


	' Open a new drawing
	ThisDrawing.Application.Documents.Add "acad.dwt"


	' Define the import
	Dim importFile As String
	Dim insertPoint(0 To 2) As Double
	Dim scalefactor As Double
	importFile = tempPath & dxfname & ".dxf"
	insertPoint(0) = 0: insertPoint(1) = 0: insertPoint(2) = 0
	scalefactor = 2#


	' Import the file
	ThisDrawing.Import importFile, insertPoint, scalefactor
	ThisDrawing.Application.ZoomAll


End Sub