here's a macro I wrote to copy the filename to the Part Number iProperty for all parts and sub-assemblies contained in a top-level assembly. I wrote this after using a bunch of custom iParts and all the Part Numbers were the same for each part! (my fault of course, but a pain to fix one at a time). Use at your own risk. Enjoy!
--------------------------------------------------------------------------
Public Sub SetAllComponentPartNumbersToFileName()
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = GetActiveAssembly
If oAsmDoc Is Nothing Then Exit Sub
SetAssemblyComponentPartNumbersToFileName oAsmDoc
End Sub
Public Function GetActiveAssembly() As AssemblyDocument
If ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then
Set GetActiveAssembly = ThisApplication.ActiveDocument
Else
MsgBox "Must have an assembly active", vbOKOnly, "Error"
End If
End Function
Public Function SetAssemblyComponentPartNumbersToFileName(oAsmDoc As AssemblyDocument)
Dim sFile As String
Dim sPart As String
Dim oDoc As Document
Dim oPropSet As PropertySet
Dim oProp As Property
Dim oRefFileDesc As ReferencedFileDescriptor
For Each oRefFileDesc In oAsmDoc.ReferencedFileDescriptors
If oRefFileDesc.DocumentType = kPartDocumentObject _
Or oRefFileDesc.DocumentType = kAssemblyDocumentObject Then
' get the part number string
sFile = oRefFileDesc.FullFileName
sPart = Right(sFile, Len(sFile) - InStrRev(sFile, "\"))
sPart = Left(sPart, InStrRev(sPart, ".") - 1)
Set oDoc = oRefFileDesc.ReferencedDocument
' get part number iProp
Set oPropSet = oDoc.PropertySets.Item("Design Tracking Properties")
Set oProp = oPropSet.Item("Part Number")
oProp.Value = sPart
End If
' recursive to descend into all assemblies
If oRefFileDesc.DocumentType = kAssemblyDocumentObject Then
SetAssemblyComponentPartNumbersToFileName (oRefFileDesc.ReferencedDocument)
End If
Next oRefFileDesc
End Function