Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instance ID change 1

Status
Not open for further replies.

Timelord

Mechanical
Dec 18, 2002
454
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
 
Replies continue below

Recommended for you

I believe that the way SW "counts" the instances is hard-coded into the software so, short of changing the code, there doesn't appear to be a way to change it.
Now that I've posted this, someone is probably going to come along and tell you how to do it...

Jeff Mirisola, CSWP
Dell M90, Core2 Duo
4GB RAM
Nvidia 3500M
 
So, what you really want is a quick count of components, not necessarily a change in the instance ID? In that case a quick macro may really be what you want. Map it to a button, then you can select a component (either a part or a subassembly), either in the graphics area or the tree and run the macro. You can choose to count top level only or count the entire assembly and all subassemblies. However, please note that any instance of the component that is inside a suppressed subassembly will not be found.

Code:
Dim swApp As SldWorks.SldWorks
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
 
Thanks for helping,

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
 
So, just to clarify, your solution was to eliminate the out-of-sequence instances of the part; save the assy; quit and re-start SW, and then re-insert the parts

Is that correct?

[cheers]
 
CorBlimeyLimey,

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
 
Deleting parts, closing files, and restarting Solidworks is simpler than running a macro? Of course, everyone's files, assemblies, situations, and applications are different, but in my case finding the highest instance number would require scrolling around the feature tree, expanding all patterns, etc. A single click of a button seems much simpler to me.
 
Handleman,

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
 
If your solution works in your situation then I'm pleased for you. But if you have to do this for a more complex assy, in which the parts have in-context relations to other parts, then a complete rebuild could ensue. Also consider that if the design changes again, then your solution could also end up being just a workaround? How often will you repeat your solution on the same assy?

Handlemans macro or the AssemblyBOM macro from give a quick count of components without relying on consecutive ID numbers. IMO that makes them far more accurate as they eliminate the possibility of human error when manually checking the numbers. Having either of those macros readily available will save you time the next time non-consecutive numbers occur ... and they will ... often. Especially if you work with assys created by other people who are more interested in producing a working design rather than keeping mostly-meaningless numbers consecutive.

If your solution took say 10 minutes, then you could have run either macro about 40 times.

[cheers]
 
Sorry if my post offended you. That was certainly not my intent. That's why I prefaced my statement with

"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!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor