Hide Table of Contents

Import DXF File to Drawing Example (VBA)

This example shows how to import a DXF file to a drawing.

'--------------------------------------
' Preconditions: Verify that the specified DXF file exists.
'
' Postconditions:
' 1. Imports the specified file into SOLIDWORKS.
' 2. Examine the drawing.
'---------------------------------------
Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim filename As String
    Dim boolstatus As Boolean
    Dim longerrors As Long
    filename = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\importexport\rainbow.DXF"
    Set swApp = Application.SldWorks
' Get the specified DXF/DWG import data
    Dim importData As SldWorks.ImportDxfDwgData
    Set importData = swApp.GetImportFileData(filename)
' To let SOLIDWORKS determine an appropriate input file unit, do not set the LengthUnit property
'    importData.LengthUnit("") = SwConst.swLengthUnit_e.swMETER
'    importData.LengthUnit("") = SwConst.swLengthUnit_e.swFEET
'    importData.LengthUnit("Model") = SwConst.swLengthUnit_e.swFEET
'    importData.LengthUnit("Sheet2") = SwConst.swLengthUnit_e.swMETER
' To let SOLIDWORKS determine an appropriate output paper size, do not set the PaperSize values
'    boolstatus = importData.SetPaperSize("", SwConst.swDwgPaperSizes_e.swDwgPaperA3size, 0#, 0#)
'    boolstatus = importData.SetPaperSize("", SwConst.swDwgPaperSizes_e.swDwgPaperEsize, 0#, 0#)
'    boolstatus = importData.SetPaperSize("", SwConst.swDwgPaperSizes_e.swDwgPapersUserDefined, 0.5, 0.8)
'    boolstatus = importData.SetPaperSize("Model", SwConst.swDwgPaperSizes_e.swDwgPaperA3size, 0.5, 0.8)
'    boolstatus = importData.SetPaperSize("Sheet2", SwConst.swDwgPaperSizes_e.swDwgPapersUserDefined, 0.16, 0.14)
' To let SOLIDWORKS determine an appropriate sheet scale, do not set the SheetScale values
'    boolstatus = importData.SetSheetScale("", 1#, 12#)
'    boolstatus = importData.SetSheetScale("Model", 1#, 3#)
'    boolstatus = importData.SetSheetScale("Sheet2", 1#, 1#)
' To let SOLIDWORKS determine an appropriate sheet name, do not set the SheetName property
'    importData.SheetName("Model") = "S1"
'    importData.SheetName("Sheet2") = "S2"
' Load the specified DXF/DWG file
    Dim newDoc As SldWorks.ModelDoc2
    Set newDoc = swApp.LoadFile4(filename, "", importData, longerrors)
End Sub


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Import DXF File to Drawing Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2018 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.