9 Replies Latest reply on Apr 6, 2018 12:08 PM by Deepak Gupta

    Export to Dxf Macro

    Mário Neto

      Hi!

       

      I've been trying to adept a macro to export part to dxf and change it's name with a custom property (sheet metal thickness) but it's now working. Something wrong in the last line. Can someone help me?

       

      Option Explicit

       

       

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swPart As SldWorks.PartDoc

      Dim sModelName As String

      Dim sPathName As String

      Dim varAlignment As Variant

      Dim dataAlignment(11) As Double

      Dim varViews As Variant

      Dim dataViews(1) As String

      Dim options As Long

      Dim FileName As String

      Dim FileSaveName As String

      Dim swModelExt As ModelDocExtension

      Dim swCustProp As CustomPropertyManager

      Dim val As String

      Dim valout As String

      Dim bool As Boolean

       

       

       

       

       

       

      Sub main()

       

       

          Set swApp = Application.SldWorks

          Set swPart = swApp.ActiveDoc

          Set swModelExt = swPart.Extension

          Set swCustProp = swModelExt.CustomPropertyManager("")

         

        

          bool = swCustProp.Get4("Espessura", False, val, valout)

          FileName = swPart.GetTitle

          FileSaveName = valout & "mm" & " " & "-" & " " & FileName

          sModelName = swPart.GetPathName

          sPathName = sModelName

          sPathName = Left(sPathName, Len(sPathName) - 18)

          sPathName = sPathName & FileSaveName & ".dxf"

        

       

       

          Set swPart = swModel

        

       

       

          dataAlignment(0) = 0#

          dataAlignment(1) = 0#

          dataAlignment(2) = 0#

          dataAlignment(3) = 1#

          dataAlignment(4) = 0#

          dataAlignment(5) = 0#

          dataAlignment(6) = 0#

          dataAlignment(7) = 1#

          dataAlignment(8) = 0#

          dataAlignment(9) = 0#

          dataAlignment(10) = 0#

          dataAlignment(11) = 1#

        

       

       

          varAlignment = dataAlignment

        

       

       

          dataViews(0) = "*Current"

          dataViews(1) = "*Front"

        

       

       

          varViews = dataViews

        

       

       

          'Export each annotation view to a separate drawing file

          'swPart.ExportToDWG2 sPathName, sModelName, swExportToDWG_ExportAnnotationViews, False, dataAlignment, False, False, 0, varViews

        

       

       

          'Export sheet metal to a single drawing file

          options = 1   'include flat-pattern geometry

          swPart.ExportToDWG2 sPathName, sModelName, swExportToDWG_ExportSheetMetal, True, varAlignment, False, False, options, Null

       

       

       

      End Sub