If you need to use an AutoCAD drawing in another application, you can convert it to a specific format by using the Export method.
The Export method exports a 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 DXFExport.dxf, opens a new drawing, and imports the file. Note that an empty selection set is provided as an argument to the Export method. The Export method ignores selection set information when exporting a DXF file, but a syntax error results if the argument is omitted.
- AutoLISP
-
(defun c:Ch3_ImportingAndExporting() (setq acadObj (vlax-get-acad-object) doc (vla-get-ActiveDocument acadObj) moSpace (vla-get-ModelSpace doc) acadPref (vla-get-Preferences acadObj)) ;; Create the circle for visual representation (setq centerPt (vlax-3d-point 2 2 0) radius 1)CH3_IMPORTINGANDEXPORTING (setq circleObj (vla-AddCircle moSpace centerPt radius)) (vla-ZoomAll acadObj) ;; Create an empty selection set (setq sset (vla-Add (vla-get-SelectionSets doc) "NEWSSET")) ;; Export the current drawing to a DXF file in the ;; AutoCAD temporary file directory (setq dxfname "DXFExport" tempPath (vla-get-TempFilePath (vla-get-Files acadPref)) exportFile (strcat tempPath dxfname)) (vla-Export doc exportFile "DXF" sset) ;; Delete the empty selection set (vla-Delete (vla-Item (vla-get-SelectionSets doc) "NEWSSET")) ;; Open a new drawing (setq newDoc (vla-Add (vla-get-Documents acadObj) "acad.dwt")) ;; Define the import (setq importFile (strcat tempPath dxfname ".dxf") insertPoint (vlax-3d-point 0 0 0) scalefactor 2) ;; Import the file (vla-Import newDoc importFile insertPoint scalefactor) (vla-put-ActiveDocument acadObj newDoc) ;; Using vla-PostCommand instead of vla-ZoomAll because ;; the document might not be current yet (vla-PostCommand newDoc "_zoom a ") )
- VBA (AutoCAD Only)
-
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 = "DXFExport" 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 Dim newDoc As AcadDocument Set newDoc = 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