25 Replies Latest reply on Mar 22, 2018 2:06 PM by Mário Neto

    Make a macro loop throughout parts of an Assembly and its subassemblies

    Mário Neto

      Hi!

       

       

      I have a macro that exports a part into a dxf file, but, how can i make it loop through every part in an assembly (Including the ones inside subassemblies)?

       

      Here's the macro:

       

      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 swModel = swApp.ActiveDoc

          Set swModelExt = swModel.Extension

          Set swCustProp = swModelExt.CustomPropertyManager("")

         

        

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

          FileName = swModel.GetTitle

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

          sModelName = swModel.GetPathName

          sPathName = InputBox("Local para Exportação")

          sPathName = sPathName & "\" & FileSaveName & ".dxf"

        

       

       

          Set swPart = swModel

        

       

       

          dataAlignment(0) = 0#

          dataAlignment(1) = 0#

          dataAlignment(2) = 0#

          dataAlignment(3) = 0#

          dataAlignment(4) = 0#

          dataAlignment(5) = 0#

          dataAlignment(6) = 0#

          dataAlignment(7) = 0#

          dataAlignment(8) = 0#

          dataAlignment(9) = 0#

          dataAlignment(10) = 0#

          dataAlignment(11) = 0#

        

       

       

          varAlignment = dataAlignment

        

         '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