-
Re: How to change the instance ID number in assemblies
Chris Mackedanz Mar 18, 2015 10:48 AM (in response to Sam Moss)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 Mar 18, 2015 11:09 AM (in response to Sam Moss)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
Glenn Schroeder Mar 18, 2015 12:06 PM (in response to Kelvin Lamport)I agree with Kelvin. Ignore that number. If you need a count of parts, that's what a BOM is for.
-
Re: How to change the instance ID number in assemblies
Chris Mackedanz Mar 18, 2015 4:19 PM (in response to Glenn Schroeder)When you want to start to use macros and the API to handle things having those instance counts go in order REALLY helps out. So there are times where having them make sense is worth it.
-
Re: How to change the instance ID number in assemblies
Kelvin Lamport Mar 18, 2015 6:23 PM (in response to Chris Mackedanz)I would have thought having them not change when an instance is removed would be even more important when using macros and the API.
-
Re: How to change the instance ID number in assemblies
Sam Moss Mar 19, 2015 3:07 AM (in response to Kelvin Lamport)I think what Chris is referring to is if you make an assembly and then run a macro, it's more elegant to have instant counts [1,2,3] than to have a work around with a clause saying:
If instance doesn't exist
i=i+1
Luckily It's not an important issue for me, I just find it incredibly annoying. It's not worth the time to manually reset them by closing and reopening, nor is it worth wasting time writing a macro (which I assume must be possible). I just wanted to know if there was a simple workaround. Looks like I'm just going to have to live with it :L.
-
-
-
-
-
Re: How to change the instance ID number in assemblies
Alice Caspari May 13, 2015 3:45 PM (in response to Sam Moss)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
Keith Rice May 13, 2015 4:07 PM (in response to Alice Caspari)In the API, when you get a component name the instance number is included, but when you change the name, it doesn't affect the instance number.
Keith
-
-
Re: How to change the instance ID number in assemblies
Brendan Owen Jan 14, 2016 5:26 AM (in response to Sam Moss)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 Sep 12, 2018 5:24 PM (in response to Sam Moss)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