10 Replies Latest reply on Sep 12, 2018 5:24 PM by Tyler Greer

    How to change the instance ID number in assemblies

    Sam Moss

      In an assembly I have had to delete and reinsert parts, this causes the instance count to be incorrect. For example I have only two parts, but they are labelled 6 and 7. Is there any way of changing this without restarting the session?

        • Re: How to change the instance ID number in assemblies
          Chris Mackedanz

          What version are you running?

           

          I'm still running 2012, and if you are referring to the number in the <>.  No, the only way to get them to "reset" is to remove all of them ( or up to where the numbers start to skip ) then CLOSE solidworks completely and then relaunch and re insert the parts.  This will force solidworks to "forget" that you had inserted those other components and start number the instance id where the last one left off at.

           

          IT'S SUPER ANNOYING!!!!!  And has been brought MANY times before.  (I'm not sure if it has been changed in newer versions or not)

          • Re: How to change the instance ID number in assemblies
            Kelvin Lamport

            The <ID> number is just that, a number used to identify a specific instance of a component.

            It is not supposed to be used for an accurate count of the number of instances.

            • Re: How to change the instance ID number in assemblies
              Alice Caspari

              I have run into this being an issue when using Macros. You may want to post this in the API section and see if anyone has a solution.

              • Re: How to change the instance ID number in assemblies
                Brendan Owen

                Hello,

                you might have found this solution already but here is what I do now. While in the assembly in question, create a subassembly containing all the components you want to renumber (identical or diff. configurations of the same part) and then dissolve the subassembly again. If you leave SW open while doing this the instance IDs will start with the next highest number but will be consecutive. If you save the file first and close SW and then re-open and then dissolve the subassembly the instance IDs will start with 1... . Props go to danuberacer, member at CAD.de (post 05.Dez.2011, Subject: "Kennung in Baugruppe manuell ändern? "

                Hope this helps,

                Brendan

                • Re: How to change the instance ID number in assemblies
                  Tyler Greer

                  I wrote a VBA function a few years ago that returns the full part name of a part in an assembly with the Solidworks instance ID number. 

                   

                  You can use the  "WhichInstanceToGet" parameter to choose which "instance number" in the assembly to get the name for.

                  You can also use the "GetIterationNumberOnly" parameter to just return the Solidworks instance ID number instead of the part name.

                   

                  Here are a couple of examples of using this function to get the part name in an assembly named "Assembly1":

                   

                  (If I was wanting to get the part name in the assembly for the 1st part named "Lifting Lug")

                   

                  Dim strSWPartName as String

                  strSWPartName = strPartNameWithSWIterationNumber("Lifting Lug-xxx@Assembly1")

                   

                   

                  And if I was wanting to get the part name in the assembly for the 3rd part named "Lifting Lug")

                   

                  Dim strSWPartName as String

                  strSWPartName = strPartNameWithSWIterationNumber("Lifting Lug-xxx@Assembly1", , , , , 3)

                   

                   

                  The function returns the part name with the correct SW instance number in place of "xxx"

                   

                  You can also pass in "yyy" and "zzz" placeholders with the strPartName parameter to get parts within sub-assemblies

                   

                  -----------------------------------

                   

                  Function strPartNameWithSWIterationNumber(strPartName As String, Optional swApp As SldWorks.SldWorks, Optional swModel As SldWorks.modelDoc2, Optional SelectingObjectInDrawingView As Boolean, Optional MaxNumberToLookThru As Integer = 10, Optional WhichInstanceToGet As Integer = 1, Optional GetNumberOnly As Boolean, Optional GetIterationNumberOnly As Boolean, Optional IterationNumberToStartAtForXXX As Integer = 1, Optional IterationNumberToStartAtForYYY As Integer = 1, Optional IterationNumberToStartAtForZZZ As Integer = 1) As String

                   

                  'created 8/19/2015 by Tyler Greer

                   

                  If swApp Is Nothing Then

                      Set swApp = GetObject(, "SldWorks.Application")

                      Set swModel = swApp.ActiveDoc

                  End If

                   

                  If swModel Is Nothing Then

                      Exit Function

                  End If

                   

                  Dim SWIterationNumber As Integer

                  Dim SWIterationNumber2 As Integer

                  Dim SWIterationNumber3 As Integer

                  Dim boolstatus As Boolean

                  Dim swComp As Object ' SldWorks.Component2

                  Dim strPartName2 As String

                  Dim WhichInstanceLastFound As Integer

                   

                  'WhichInstanceToGet    default is 1 - it will get the first one of this part

                   

                  For SWIterationNumber = IterationNumberToStartAtForXXX To IIf(WhichInstanceToGet > MaxNumberToLookThru, WhichInstanceToGet, MaxNumberToLookThru)

                      If InStr(1, strPartName, "yyy") > 0 Then

                          For SWIterationNumber2 = IterationNumberToStartAtForYYY To MaxNumberToLookThru

                              If InStr(1, strPartName, "zzz") > 0 Then

                                  For SWIterationNumber3 = IterationNumberToStartAtForZZZ To MaxNumberToLookThru

                                      strPartName2 = Replace(Replace(Replace(strPartName, "yyy", CStr(SWIterationNumber2)), "xxx", CStr(SWIterationNumber)), "zzz", CStr(SWIterationNumber3))

                                 

                                      boolstatus = swModel.Extension.SelectByID2(strPartName2, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

                                 

                                      If CBool(Abs(boolstatus)) = True Then

                                          WhichInstanceLastFound = WhichInstanceLastFound + 1

                                         

                                          If WhichInstanceToGet = WhichInstanceLastFound Then

                                              GoTo FoundPartName

                                          End If

                                      End If

                                  Next SWIterationNumber3

                              Else

                                  strPartName2 = Replace(Replace(strPartName, "yyy", CStr(SWIterationNumber2)), "xxx", CStr(SWIterationNumber))

                             

                                  boolstatus = swModel.Extension.SelectByID2(strPartName2, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

                             

                                  If CBool(Abs(boolstatus)) = True Then

                                      WhichInstanceLastFound = WhichInstanceLastFound + 1

                                     

                                      If WhichInstanceToGet = WhichInstanceLastFound Then

                                          GoTo FoundPartName

                                      End If

                                  End If

                              End If

                          Next SWIterationNumber2

                      Else

                          strPartName2 = Replace(strPartName, "xxx", CStr(SWIterationNumber))

                          boolstatus = swModel.Extension.SelectByID2(strPartName2, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

                      End If

                         

                      If CBool(Abs(boolstatus)) = True Then

                  'I added these lines 9/21/2015 - because if I am selecting an object in a drawing view, then it will select it no matter what iteration number it has

                          WhichInstanceLastFound = WhichInstanceLastFound + 1

                         

                          If WhichInstanceToGet = WhichInstanceLastFound Then

                              If SelectingObjectInDrawingView = True Then

                                  Set swComp = swModel.SelectionManager.GetSelectedObject6(1, -1)

                                  strPartName2 = swComp.Name

                              End If

                             

                              GoTo FoundPartName

                          Else

                              strPartName2 = "" 'added 7/26/2016

                          End If

                      Else

                          strPartName2 = ""

                      End If

                  Next SWIterationNumber

                   

                  FoundPartName:

                  If CBool(Abs(boolstatus)) = True Then

                      If GetNumberOnly = True Then

                          strPartNameWithSWIterationNumber = CStr(WhichInstanceLastFound)

                      ElseIf GetIterationNumberOnly = True Then

                          strPartNameWithSWIterationNumber = CStr(SWIterationNumber)

                      Else

                          strPartNameWithSWIterationNumber = strPartName2

                      End If

                  End If

                   

                  End Function