11 Replies Latest reply on Feb 15, 2019 2:19 PM by Mehmet Gultepe

    how to import multiple step files?  Macro?  #task?

    Dan Golthing

      OEM vehicle files are sometimes hundreds if not thousands of step or igs imports.

       

      Open...wait...Save.

      Open...wait...Save.

      Open...wait...Save.

      ad infinitum.

       

      you get the idea. 

       

      Any suggestions how to automate this process?

       

      I was looking in task and there's a "Import 3D" macro, but I haven't yet been able to get it to do anything.

       

      I'd like to select a folder and have each file opened in SWX and then saved back to the same folder.  I have a few hundred folders just of one vehicle and in each folder there can be up to a hundred files.

        • Re: how to import multiple step files?  Macro?  #task?
          Bjorn Hulman

          Hi Dan,

          #TASK is definitely the first avenue I would explore

          • Re: how to import multiple step files?  Macro?  #task?
            Dan Golthing

            Now that this is running well in #task one problem is that it isn't doing import diagnostics on the imported bodies.  Many of these, if diagnosed, will converge back into a solid instead of a surface.

             

            If anyone from task can let us know if this is possible, to add import diagnostics to the import 3D macro...

             

            thanks

              • Re: how to import multiple step files?  Macro?  #task?
                Bjorn Hulman

                Will the import settings not help get what you require Dan?

                  • Re: how to import multiple step files?  Macro?  #task?
                    Dan Golthing

                    I'll give that a try.  Thanks.

                      • Re: how to import multiple step files?  Macro?  #task?
                        Mehmet Gultepe

                        I hope this can help you. I tried to use #Task and I don't find it useful. My macro runs a lot faster than this #Task and I can also modify my codes for my need. Check this macro that I have. I put all the step files in one folder in my ram disk and run this macro. this macro will ask you the folder that you put the step files in, navigate thru and select the folder and hit ok. it will run all the step files one by one and save as part even if it's assembly file. I am looking for to add Import Diagnostics into this program because sometimes it brings step files as surface and it puts too much load to the computers so Import Diagnostics heals the surface model and converts to solid.

                         

                         

                        ' ------------------------------------------------------------------------------

                        Option Explicit

                        Dim swApp        As SldWorks.SldWorks
                        Dim swModel      As SldWorks.ModelDoc
                        Dim sFileName    As String, Path As String
                        Dim boolstatus   As Boolean
                        Dim longstatus   As Long, longwarnings As Long
                        Dim FileName            As String
                        Dim swDocSpecification  As SldWorks.DocumentSpecification
                        Dim swModelTitle                As SldWorks.ModelDoc2

                        Dim NewFilePath         As String
                        Dim PathNoExtension     As String
                        Dim FilePath            As String
                        Dim PathSize            As Long


                        Public Type BROWSEINFO
                            hOwner          As LongPtr
                            pidlRoot        As LongPtr
                            pszDisplayName  As String
                            lpszTitle       As String
                            ulFlags         As LongPtr
                            lpfn            As LongPtr
                            lParam          As LongPtr
                            iImage          As LongPtr
                        End Type

                        Public Const BIF_RETURNONLYFSDIRS = &H1
                        Public Const BIF_DONTGOBELOWDOMAIN = &H2
                        Public Const BIF_STATUSTEXT = &H4
                        Public Const BIF_RETURNFSANCESTORS = &H8
                        Public Const BIF_BROWSEFORCOMPUTER = &H1000
                        Public Const BIF_BROWSEFORPRINTER = &H2000
                        Public Const BIF_NEWDIALOGSTYLE = &H40

                        Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As LongPtr, ByVal pszPath As String) As LongPtr
                        Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPtr

                         
                        Sub main()
                            Dim FolderPath          As String

                           
                           
                            'Go to GetFolder function to browse to the desiered folder
                            FolderPath = GetFolder("Select the Folder you want to use")
                           
                            Set swApp = Application.SldWorks
                            swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swAlwaysUseDefaultTemplates, True
                            swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swMultiCAD_Enable3DInterconnect, False
                            swApp.SetUserPreferenceToggle swImportStlVrmlModelType_e.swImportStlVrmlModelType_Solid, True
                            swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swSaveAssemblyAsPartOptions, 2

                            Path = FolderPath + "\"
                           
                            
                            sFileName = Dir(Path & "\" & "*.stp")  ' Change .x_t to any other extension you need.
                           
                                Do Until sFileName = ""
                                boolstatus = swApp.LoadFile(Path + sFileName)
                              
                                Set swModel = swApp.ActiveDoc

                               
                                PathSize = Strings.Len(Path + sFileName)
                                PathNoExtension = Strings.Left(Path + sFileName, PathSize - 4)
                                NewFilePath = PathNoExtension & ".SLDPRT"
                                longstatus = swModel.SaveAs(NewFilePath)
                                 
                               
                                swApp.CloseDoc swModel.GetTitle
                                Set swModel = Nothing
                                  
                                sFileName = Dir
                                  
                                Loop
                           
                             sFileName = Dir(Path & "\" & "*.step")
                          
                                Do Until sFileName = ""
                           
                                boolstatus = swApp.LoadFile2(Path + sFileName, "")
                              
                                Set swModel = swApp.ActiveDoc
                               
                               
                                PathSize = Strings.Len(Path + sFileName)
                                PathNoExtension = Strings.Left(Path + sFileName, PathSize - 5)
                                NewFilePath = PathNoExtension & ".SLDPRT"
                                longstatus = swModel.SaveAs(NewFilePath)
                                 
                               
                                swApp.CloseDoc swModel.GetTitle
                            Set swModel = Nothing
                          
                            sFileName = Dir
                              
                            Loop
                           
                          
                        End Sub
                        'Open the browse window to select the folder
                        Public Function GetFolder(ByVal sTitle As String) As String
                           
                            Dim bInf            As BROWSEINFO
                            Dim retval          As LongPtr
                            Dim PathID          As LongPtr
                            Dim RetPath         As String
                            Dim Offset          As Integer

                            bInf.lpszTitle = sTitle
                            bInf.ulFlags = BIF_NEWDIALOGSTYLE
                            PathID = SHBrowseForFolder(bInf)
                            RetPath = Space$(512)

                            retval = SHGetPathFromIDList(ByVal PathID, ByVal RetPath)

                            If retval Then
                                Offset = InStr(RetPath, Chr$(0))
                                GetFolder = Left$(RetPath, Offset - 1)
                            End If
                           
                        End Function