3 Replies Latest reply on Nov 28, 2018 10:08 AM by David Charron

    Macro for importing inventor files and saving in .step

    David Charron

      Hi, I need help to complete this macro.

       

      I use a form to specify path of folder containing .iam and .ipt files.

      I want to save them in .step, in the same folder or sub-folder.

      I want to run this macro with Task Scheduler

       

      Please see in attachment.

       

      Seems I'm not far from a solution.

       

      Thanks All!

       

      DC

        • Re: Macro for importing inventor files and saving in .step
          Niels Raahauge

          'I think this code can help you ... 

           

          Dim swApp As SldWorks.SldWorks

          Dim swDoc As ModelDoc2

          Dim fileerror As Long

          Dim filewarning As Long

           

          Const folder As String = "C:\Path_with_sw\"

          Dim files As Variant

              

          Sub main()

              Set swApp = Application.SldWorks

              files = Dir(folder & "*.sldprt", vbNormal)

              Do While files <> ""

                  swApp.OpenDoc6 folder & files, swDocPART, 0, "", fileerror, filewarning

                  files = Dir

              Loop

          End Sub

          • Re: Macro for importing inventor files and saving in .step
            David Charron

            Dim swApp               As SldWorks.SldWorks

            Dim swModel             As SldWorks.ModelDoc2

            Dim sSearchPath         As String

            Dim sFileName           As String

            Dim objFolder           As Folder

            Dim fso                 As FileSystemObject

            Dim objFile             As File

            Private Sub CButton1_Click()

             

             

            'MsgBox ("macro started")

            Set swApp = Application.SldWorks

            Dim error As Long

             

             

            'SEARCH FOR THE FILES

            sSearchPath = fMain.TextBox1.Text

            Dim fso As New FileSystemObject

            Dim bRet As Boolean

             

             

            Set objFolder = fso.GetFolder(sSearchPath)

            'MsgBox (objFolder.Name)

             

             

            For Each objFile In objFolder.Files

            'MsgBox (objFile.Path)

            'open the file found - file type to be changed

                If LCase(Right(objFile.Path, 3)) = "ipt" Or LCase(Right(objFile.Path, 3)) = "iam" Then

               

               ' MsgBox (objFile.Name)

                    bRet = swApp.LoadFile2(objFile.Path, "r") 'Load Inventor file

                    Set swModel = swApp.ActiveDoc

                   

            'save & close -

                    sFileName = Left(objFile.Name, InStrRev(objFile.Name, ".") - 1)

                    swModel.SaveAs (sFileName & ".step")

                    swApp.CloseDoc swModel.GetTitle

                    MsgBox (objFile.Name & "was converted")

                Else

                    MsgBox ("not converted! Verify it is a part!")

                End If

            Next objFile

             

             

            MsgBox ("Done")

             

             

            End Sub

             

             

             

             

            Private Sub UserForm_Click()

             

             

            End Sub