3 Replies Latest reply on Feb 22, 2017 9:12 AM by Deepak Gupta

    Macro to save parts in assembly as step. in directory

    Daniel Aaskov

      Hi All.

      My first post here, firstly let me thank you.

       

      I would like a macro that does the following, open each part of an assembly and saves the part as a step and the drawing as PDF.

      The STEP and PDF should then be saved in an already existing folder that has the same name as the part.

       

      Can someone help me? I'm not that experienced with macro programming.

       

      Thank you

        • Re: Macro to save parts in assembly as step. in directory
          Deepak Gupta

          Daniel, you can try this tool #TASK

           

          OR try the macros posted here Macro to export model as .step file

           

          You'll have to modify these to suit your needs.

            • Re: Macro to save parts in assembly as step. in directory
              Daniel Aaskov

              Hi Deepak.

              Thank you very much! I'm building my script based on that.

               

              Maybe you could help me with a minor detail?

              Lets say,

              A part is called "XXX-XXXX".sldprt and should be saved as a step and pdf in a folder called "C:\Documents\XXX-XXX-bla bla bla"

              Note the folder has the same name as the part with the exception of a random text.

               

              How do i define the path? To be "C:\Documents\XXX-XXX-bla bla bla" when "bla bla bla" is a variable and only the name XXX-XXXX is constant.

               

              Hope it makes sense.

                • Re: Macro to save parts in assembly as step. in directory
                  Deepak Gupta

                  You can use these codes as changes as needed.

                   

                  Option Explicit
                      Dim swApp          As SldWorks.SldWorks
                      Dim swModel        As SldWorks.ModelDoc2
                      Dim FileName        As String
                      Dim FilePath        As String
                      Const FolderName    As String = "Test" 'Change variable here
                     
                  Sub Main()
                      Set swApp = Application.SldWorks
                      Set swModel = swApp.ActiveDoc
                     
                      FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
                      FileName = Left(FileName, InStrRev(FileName, ".") - 1)
                     
                      FilePath = "C:\Documents\" & FolderName & "-" & FileName 'Change Path as needed
                     
                      If Dir(FilePath, vbDirectory) = "" Then
                              MkDir FilePath
                      End If
                     
                      FilePath = FilePath & "\"
                     
                      Debug.Print FilePath
                     
                  End Sub