3 Replies Latest reply on Jun 28, 2018 4:13 AM by Simon Turner

    Import Step File - Problem

    Darren Smith

      Can anybody help????


      I have attached a macro, and a sample "step" file


      From the macro, I want to do the following.....


      Load a Step File. (Everything is OK)

      Delete all "file properties" that might have been loaded with the step file.(Everything is OK)

      Add my own "file properties" (Everything is OK)


      If you look at the "file properties" you will see the ones that I have added.


      Then I want to save the step file as a "sldprt" in a specific folder.


      The problem is.....


      I can save the part to a specific folder, but, I always have to re-save the part before closing it, even though I have saved the part using the macro.


      When I open the file that I have just saved, using the macro, the "file properties" have disappeared.


      Does anybody know what I am doing wrong????






      P.S, you will have to update the macro to load/save the step file to/from your own folder locations.

        • Re: Import Step File - Problem
          Simon Turner

          Your step file contains an assembly, which you then try to save as a part.

          So it saves a copy and gets rid of the assembly where you have edited the properties.

          You need to save the file as a .sldasm document.

          • Re: Import Step File - Problem
            Deepak Gupta

            The properties you are adding is actually getting added to the imported assembly file. So you need to close the assembly, open the saved part file and add properties to that. Here is a code you can try


            Option Explicit
                Dim swApp                          As SldWorks.SldWorks
                Dim swModel                        As SldWorks.ModelDoc2
                Dim bRet                            As Boolean
                Dim swImportData                    As SldWorks.ImportIgesData
                Dim Err                            As Long
                Dim Foldername                      As String
                Dim PartNumber                      As String
                Dim PartDescription                As String
                Dim SupplierPartNumber              As String
                Dim PartFileName                    As String
                Dim nErrors                        As Long
                Dim nWarnings                      As Long
            Sub Main()
                Foldername = "C:\PDA"
                PartNumber = "3231545353"
                PartDescription = "DARRENS TEST"
                SupplierPartNumber = "1234567890"
                Set swApp = Application.SldWorks
                Set swModel = swApp.LoadFile4("C:\Users\User\Downloads\io1-ac-214.step", "r", swImportData, Err)
                PartFileName = Foldername + "\" + SupplierPartNumber + ".sldprt"
                Err = swModel.SaveAs3(PartFileName, 0, 0)
                swApp.CloseDoc swModel.GetTitle
                Set swModel = swApp.OpenDoc6(PartFileName, swDocPART, swOpenDocOptions_Silent, "", nErrors, nWarnings)
                bRet = swModel.AddCustomInfo3("", "Part: Number", 30, PartNumber)
                bRet = swModel.AddCustomInfo3("", "Part: Description", 30, PartDescription)
            End Sub


            Always use "Option Explicit" as with this you won't miss to define the variables. Also you are using many obsolete/old codes/method, so look in API help files and update them to latest one.