9 Replies Latest reply on Feb 11, 2016 12:10 PM by Deepak Gupta

    rename / pack and go to sequential numbers

    Philip Edwards

      I have an assembly containing 500+ parts, the file names of these parts are no longer relevant, i want to Pack and go, but instead of using the select / replace command, as the old part names are obscure, so would have to search each one individually, i want to give new sequential part numbers to all the files. i want to rename the new files 1,2,3,4,5....... i will then re-pack and go, to add the companies naming convention to the start of the file name.












        • Re: rename / pack and go to sequential numbers
          John Stoltzfus

          That is tricky - I have done that in the past, but you have to be very careful or you'll end up with a huge mess that you can't do anything with, because of the chance of renaming two parts with the same number, that is a disaster to where it is almost impossible to fix without re-modeling from the start. 


          To convert the old numbers, here is what I would suggest, "Number One, Make A Backup copy"  2nd thing I would do is make a indented BOM with all the parts, save out the BOM as an excel file and sort, then add a column and insert the "New" part number sequence, to give you some structure.


          Now what I would do for an assembly of this size, I would do a search and replace one file at a time and use the excel file as a guide which one you're doing.  Stay away from the easy way, because the easy way can blow up quick and it will take you double the amount of time to correct.  The problem that I see is you can end up with a part that has the same last three digits, so a mass search and replace won't work.



          You could do a search and replace the "-09" but the "-02" will give you the double part.


          No easy way out of this one, once you get it totally done you can then very easily do the search and replace - pack & go

          • Re: rename / pack and go to sequential numbers
            Deepak Gupta

            It is doable using SetDocumentSaveToNames. Look under API help file for details on this fucntion.

              • Re: rename / pack and go to sequential numbers
                John Stoltzfus

                The macro only saves out assemblies and parts - could you tell us what to add and where to add it in the attached macro to also include the drawing file??



                'Off the SolidWorks forum https://forum.solidworks.com/message/546563#546563 posted by Amen Allah Jlili'



                Dim swApp As SldWorks.SldWorks

                Dim swModel As ModelDoc2

                Dim swModelDocExt As ModelDocExtension

                Dim SavingPath As String

                Sub main()

                SavingPath = InputBox("Where do you want to pack and go? Enter path here:", "PackAndGo by jliliamen@gmail.com")

                Dim FileSystemObject As Object

                Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

                If Not FileSystemObject.FolderExists(SavingPath) Then

                MsgBox ("Folder does not exist.")

                End If

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

                Set swModelDocExt = swModel.Extension

                Dim PackAndGoObj As PackAndGo

                Set PackAndGoObj = swModelDocExt.GetPackAndGo

                Dim VDocs

                Dim result As Boolean

                PackAndGoObj.FlattenToSingleFolder = True

                PackAndGoObj.IncludeToolboxComponents = True

                result = PackAndGoObj.GetDocumentNames(VDocs)

                Dim Partcounter As Long: Partcounter = 1

                Dim AssemblyCounter As Long: AssemblyCounter = 1

                For i = 0 To UBound(VDocs)

                If Split(VDocs(i), ".")(1) = "sldprt" Then

                VDocs(i) = "21116-" & Partcounter & ".sldprt"

                Partcounter = Partcounter + 1

                ElseIf Split(VDocs(i), ".")(1) = "sldasm" Then

                VDocs(i) = "21116A-" & AssemblyCounter & ".sldasm"

                AssemblyCounter = AssemblyCounter + 1

                End If

                Next i

                result = PackAndGoObj.SetSaveToName(True, SavingPath)

                result = PackAndGoObj.SetDocumentSaveToNames(VDocs)

                Dim vResult

                vResult = swModelDocExt.SavePackAndGo(PackAndGoObj)



                MsgBox "All Packed - Going Where"



                End Sub

              • Re: rename / pack and go to sequential numbers
                John Stoltzfus

                I need to undo what I just posted above, Deepak Gupta made me look


                and I found a macro that works really well, just tested it.  It names all the parts like Part-1, ect, you could change the macro by adding your own prefix, remove the name part and add your own. 


                See this post Re: Rename part files from a folder without loosing Assembly reference

                  • Re: rename / pack and go to sequential numbers
                    Philip Edwards

                    Thanks for your help so far, we are nearly there, the code seems to stop at the lines below,


                    PackAndGoObj.FlattenToSingleFolder = True

                    PackAndGoObj.IncludeToolboxComponents = True


                    So i deleted them, and the macro ran


                    this is nearly what i require, i do not want the parts and assemblies to be different, i just want the assemblies to take the next number after the parts, and drawings need to be included.

                      • Re: rename / pack and go to sequential numbers
                        John Stoltzfus

                        Mine tested out great on the parts and assemblies and I added the following to save out the drawing. 


                        But the problem with that is it does save the drawing as well, but the old parts are still in it.  i use multiple tabs in my drawing so it was only one file.  It would have to be a pretty intense open, rebuild, close and save macro to do that.  I am not a macro writer, I can make limited changes etc..

                    • Re: rename / pack and go to sequential numbers
                      Jason Edelman

                      2017 you can change the file name right in the assembly...