Hide Table of Contents

Import DXF File into Part Sketch Example (VBA)

This example shows how to import a DXF file to a part sketch.

 

'--------------------------------------

'

' Preconditions: The specified DXF file exists.

'

' Postconditions: The specified file is imported into SolidWorks.

'

'---------------------------------------

Option Explicit

 

Sub main()

 

    Dim swApp As SldWorks.SldWorks

    Dim filename As String

    Dim longerrors As Long

    Dim retVal As Boolean

    filename = "e:\samples\importdxfdwgdata\Draw3.DXF"

 

    Set swApp = Application.SldWorks

    Dim importData As SldWorks.ImportDxfDwgData

    Set importData = swApp.GetImportFileData(filename)

 

' Import method

    importData.ImportMethod("") = SwConst.swImportDxfDwg_ImportMethod_e.swImportDxfDwg_ImportToPartSketch

 

' Load the specified DXF/DWG file

    Dim newDoc As SldWorks.ModelDoc2

    Set newDoc = swApp.LoadFile4(filename, "", importData, longerrors)

 

' Gets

    Debug.Print "Part Sketch Gets:"

    Debug.Print "  Add constraints:   " & importData.AddSketchConstraints("")

    Debug.Print "  Merge points:      " & importData.GetMergePoints("")

    Debug.Print "  Merge distance:    " & (importData.GetMergeDistance("") * 1000#) & " mm"

    Debug.Print "  Import dimensions: " & importData.ImportDimensions("")

    Debug.Print "  Import hatch:      " & importData.ImportHatch("")

'Sets

    Debug.Print "Part Sketch Sets:"

    importData.AddSketchConstraints("") = True

    Debug.Print "  Add constraints:   " & importData.AddSketchConstraints("")

    retVal = importData.SetMergePoints("", True, 0.000002)

    Debug.Print "  Merge points:      " & retVal

    Debug.Print "  Merge distance:    " & (importData.GetMergeDistance("") * 1000#) & " mm"

    importData.ImportDimensions("") = True

    Debug.Print "  Import dimensions: " & importData.ImportDimensions("")

    importData.ImportHatch("") = False

    Debug.Print "  Import hatch:      " & importData.ImportHatch("")

    

    

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 into Part Sketch 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) 2010 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.