2 Replies Latest reply on Aug 5, 2013 12:22 PM by Hersh Sridhar Iyer

    Issue with Merge Points on DXF Import

    Hersh Sridhar Iyer



      I am looking to import a DXF file and extruding the sketch post import to a cetain thickness.

      The DXF import is done using the macro - http://help.solidworks.com/2013/English/api/sldworksapi/Import_DXF_File_into_Part_Sketch_Example_VB.htm.

      However, once imported, extrude on the sketch fails because of open contours which are a result of non-overlapping end points between the sketch edges.

      I was aware of this and hence depended on the "Merge Points Closer Than" check box which is provided in the DXF Import UI.


      If I import the DXF through the UI with the option to merge points (closer than 0.001) and then extrude the part, it comes out fine. The same thing done using the macro does not work. Please advise.


      Is there a way to apply the merge points setting while importing through the macro? The SetMergePoints() call does not result in the required merge.

      The DXF is attached for reference.


      Please advise.




        • Re: Issue with Merge Points on DXF Import
          Simon Turner

          First of all, you need to specify which sheet to load from the DXF. Last time I looked, you couldn't do that in the API, so I import the entire dxf as a 2D drawing, delete the unwanted sheets and then save back to DXF.


          Next, I use this code to import the new DXF to a sketch:



                      Set myImportData = swApp.GetImportFileData(myFileName)

                      myImportData.ImportMethod("") = swImportDxfDwg_ImportMethod_e.swImportDxfDwg_ImportToExistingPart

                      myImportData.SetMergePoints "", True, 0.2

                      myImportData.ImportDimensions("") = False

                      myImportData.ImportHatch("") = False

                      myImportData.LengthUnit("") = swLengthUnit_e.swMM


                      myImportData.ImportMethod(mySheetName) = swImportDxfDwg_ImportMethod_e.swImportDxfDwg_ImportToExistingPart

                      myImportData.SetMergePoints mySheetName, True, 0.2

                      myImportData.ImportDimensions(mySheetName) = False

                      myImportData.ImportHatch(mySheetName) = False

                      myImportData.LengthUnit(mySheetName) = swLengthUnit_e.swMM


                      Set myFeature = Part.FeatureManager.InsertDwgOrDxfFile2(myFileName, myImportData)

            • Re: Issue with Merge Points on DXF Import
              Hersh Sridhar Iyer

              Hi Simon,


              Thanks for the suggestion. I am not sure if the macro you suggested solves my problem which is extruding the imported DXF sketch to a specified thickness. Basically, the mergePoint call is not being honored if I use swImportDxfDwg_ImportMethod_e.swImportDxfDwg_ImportToExistingPart.


              I contacted the API support folks at SW and they  helped me out by suggesting the following macro for DXF import which uses

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

              This does the job for me now.


              Dim swApp As Object

              Dim Part As Object

              Dim boolstatus As Boolean

              Option Explicit

              Sub main()


                  Dim swApp As SldWorks.SldWorks

                  Dim filename As String

                  Dim longerrors As Long

                  Dim retVal As Boolean



                  filename = "C:\Users\hiyer\Desktop\Current\dxf\test.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


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

                  Debug.Print "  Merge points:      " & retVal



              ' Load the specified DXF/DWG file

                  Dim newDoc As SldWorks.ModelDoc2

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



                  retVal = newDoc.Extension.SelectByID2("Model", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)

                  Set Part = swApp.ActiveDoc

                  boolstatus = Part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)

                  boolstatus = Part.ChangeSketchPlane()

                  boolstatus = Part.EditRebuild3()



                  'Dim myFeature As SldWorks.Feature

                  boolstatus = Part.Extension.SelectByID2("Model", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)

              Dim myFeature As Object

              Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.00021, 0.01, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)


              End Sub