Hi,
I'm hoping to find a way to batch change the component reference value for multiple parts in an assembly.
For example - if there are multiple instances of a component in an assembly, I would like to set the component reference for each of those instances to be the same (e.g. "1"). As is, I am able to go through and manually change each component, but this is time consuming for large bills. Selecting multiple components and opening the component properties window doesn't work. The component reference value is being sent to Teamcenter as an item line number - so if I have multiple instances of the same component in a bill, and the line numbers are all the same, the lines may be combined.
Hopefully someone out there has an idea.
Thanks,
Brad
I did this exact thing using the API, the only difference being that I had the code increment the reference instead of keep it the same.
here is my code:
'Preconditions:
'Assembly document must be open
'entities belonging to components must be selected
'
'Postconditions:
'components selected will be assigned a sequential reference designator
'derived from the root and start number assigned in the userform.
Private Sub Command_Go_Click()
Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swEntity As Entity
Dim objectCount As Integer
Dim swComponent As Component2
Dim refRoot As String
Dim refNumber As Integer
ARData.Hide
refRoot = ARData.TextBox1.Text
refNumber = CInt(ARData.TextBox2.Text)
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Dim swSelectionMgr As SelectionMgr
Set swSelectionMgr = Part.SelectionManager
objectCount = swSelectionMgr.GetSelectedObjectCount
For i = 1 To objectCount
Set swEntity = swSelectionMgr.GetSelectedObject6(i, -1)
Set swComponent = swEntity.GetComponent
swComponent.ComponentReference = refRoot & CStr(refNumber)
refNumber = refNumber + 1 <------------------you could comment this line out to prevent the reference number from incrementing
Next
Part.ForceRebuild3 (True)
End Sub
I'm a complete novice with this forum so I don't know the best way to get you the complete file that I'm using, but I'd be happy to help however I can.
The way I've used this is if i have say, a hundred circuit breakers and i want to set their component reference to CB9000 to CB9099, i would just select a face from each circuit breaker in the graphics window, and start the macro. In the designator root, i would type "CB" and in the starting value i'd type "9000" and then after the macro runs I'll have references applied to each circuit breaker.
This is far from a bomb-proof solution, but I think it can get you where you need to be with a little tweaking. I hope this helps.