Instance ID change
Instance ID change
(OP)
Quick question for the Gurus,
Is there any way to change the instance ID in an assembly file? I inserted some parts and then deleted them. When I reinsert them they come in with Instance ID's that numerically skip the deleted items. This makes it more difficult to get a quick count of the inserted parts in the tree. The box showing the instance in the properties dialog is greyed out.
I am still using SW2005 SP5.0
Thanks,
Timelord
Is there any way to change the instance ID in an assembly file? I inserted some parts and then deleted them. When I reinsert them they come in with Instance ID's that numerically skip the deleted items. This makes it more difficult to get a quick count of the inserted parts in the tree. The box showing the instance in the properties dialog is greyed out.
I am still using SW2005 SP5.0
Thanks,
Timelord






RE: Instance ID change
Now that I've posted this, someone is probably going to come along and tell you how to do it...
Jeff Mirisola, CSWP
http://designsmarter.typepad.com/jeffs_blog
Dell M90, Core2 Duo
4GB RAM
Nvidia 3500M
RE: Instance ID change
CODE
Dim swDoc As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSelComp As SldWorks.Component2
Dim CurSelCount As Long
Dim GeneralSelObj As Object
Dim AllComponents As Variant
Dim i As Long
Dim TopLevOnly As Boolean
Dim SupCount As Long
Dim LwtCount As Long
Dim ResCount As Long
Dim sMsg As String
Dim CompPath As String
Dim CompConfig As String
Dim EachComp As SldWorks.Component2
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
If swDoc.GetType <> swDocASSEMBLY Then
MsgBox "This macro works for assembly documents only"
Exit Sub
End If
Set swAssy = swDoc
Set swSelMgr = swDoc.SelectionManager
CurSelCount = swSelMgr.GetSelectedObjectCount
If CurSelCount = 0 Then
MsgBox "Nothing was selected"
Exit Sub
End If
Set GeneralSelObj = swSelMgr.GetSelectedObject(CurSelCount)
Set swSelComp = swSelMgr.GetSelectedObjectsComponent(CurSelCount)
CompPath = swSelComp.GetPathName
CompConfig = swSelComp.ReferencedConfiguration
If MsgBox("Count " & swSelComp.Name2 & " in top level assembly only?", vbYesNo) = vbYes Then
TopLevOnly = True
Else
TopLevOnly = False
End If
AllComponents = swAssy.GetComponents(TopLevOnly)
SupCount = 0
ResCount = 0
LwtCount = 0
For i = 0 To UBound(AllComponents)
Set EachComp = AllComponents(i)
If UCase(EachComp.GetPathName) = UCase(CompPath) Then
If UCase(EachComp.ReferencedConfiguration) = UCase(CompConfig) Then
If (EachComp.GetSuppression = swComponentFullyResolved) Or (EachComp.GetSuppression = swComponentResolved) Then
ResCount = ResCount + 1
ElseIf EachComp.GetSuppression = swComponentLightweight Then
LwtCount = LwtCount + 1
ElseIf EachComp.GetSuppression = swComponentSuppressed Then
SupCount = SupCount + 1
End If
End If
End If
Next i
sMsg = "Usage information for:" & vbCrLf & CompPath & vbCrLf & CompConfig
If TopLevOnly Then
sMsg = sMsg & vbCrLf & "Count includes top level assembly only."
Else
sMsg = sMsg & vbCrLf & "Count includes top level and all unsuppressed subassemblies."
End If
sMsg = sMsg & vbCrLf & vbCrLf & "Resolved: " & ResCount & vbCrLf
sMsg = sMsg & "Lightweight: " & LwtCount & vbCrLf
sMsg = sMsg & "Suppressed: " & SupCount
MsgBox sMsg
End Sub
RE: Instance ID change
I found a simpler solution. I deleted the miss numbered parts, closed all the files and restarted SW. The instance ID's then came in in the correct numerical order.
Timelord
RE: Instance ID change
Is that correct?
RE: Instance ID change
That is exactly what I did. I don't know if it was necessary to restart SW, but that is what I did.
I guess it is not hard coded, so it is possible that there may be a way to reset the next instance number, something like the way you can set the next view label in a drawing, but I haven't found it.
Timelord
RE: Instance ID change
RE: Instance ID change
Yes it is simpler than running a macro. I only have to do it once and the instance numbers correctly give me the count without a single button, as often as I want to look.
Besides, I was looking for an answer to my question, not a workaround.
Timelord
RE: Instance ID change
Handlemans macro or the AssemblyBOM macro from http
If your solution took say 10 minutes, then you could have run either macro about 40 times.
RE: Instance ID change
"Of course, everyone's files, assemblies, situations, and applications are different, but in my case...
If your situation is:
1. Routinely work on small assemblies of simple parts, such that the feature tree fits on one screen without scrolling.
2. Rarely delete parts or change configurations.
3. Never use component patterns.
4. Only work on your own files.
5. Never interested in counting components inside subassemblies.
then your method may be simpler. In my case none of the above are true, so your workaround would be an entirely unacceptable workaround for the end goal, which is to get a count of a certain component in an assembly.
An amputee once went to the doctor. "Doc," he said, "I need a new hook. This one just doesn't have a sharp enough edge on it for me to scratch my head if I've got something in my other hand." The doctor said, "I have great news for you! Because of advances in medical technology, you are now a great candidate for a complete hand transplant!" The amputee left in a huff and filed a sharp edge on his old hook. "Stupid doctor, I asked for a sharper hook, not a new hand!"