One of the reasons that I suggested doing it from the top level was because I already have a bit of code banged up that writes the parts QTY (across all assemblies, even subs) into a custom iProperty. If you were to use this code (below) in the top level assembly, it would place the part qty number in the iProperty Authority ( I used authority in this example so you didn’t have to worry about making a new custom iprop in all of your parts).
It is then pretty easy to reference that iProperty across to the drawing. In our case, we have our sheet metal flat pattern views set up to display the iProperty via the Style that we’re using. You could very well do the same for a title block, or the design view that you’re throwing onto the drawing sheet.
This way it keeps your users from having to do extra work that could result in errors or blood loss.
If you could give that a shot, in the meantime, I’ll see about coding out a top level assembly selector in case it doesn’t float your boat.
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
If openDoc.DocumentType = 12291 Then
For Each docFile In openDoc.AllReferencedDocuments
If docFile.IsModifiable = True Then
If docFile.DocumentType = 12290 Then
Dim assemblyDoc As AssemblyDocument
assemblyDoc = openDoc
Dim assemblyDef As AssemblyComponentDefinition
assemblyDef = assemblyDoc.ComponentDefinition
Dim partDoc As PartDocument
partDoc = ThisApplication.Documents.Open(docFile.FullFileName, False)
Dim partQty As ComponentOccurrencesEnumerator
partQty = assemblyDef.Occurrences.AllReferencedOccurrences(partDoc)
'MessageBox.Show(partQty.Count, "")
If IsNumeric(partQty.Count) = True Then
If CDblAny(partQty.Count) <> CDblAny(iProperties.Value(docFile.DisplayName, "Project", "Authority")) Then
iProperties.Value(docFile.DisplayName, "Project", "Authority") = partQty.Count
partDoc.Close
Else
partDoc.Close
End If
End If
Else
Dim docDisplayName As String
If docFile.LevelOfDetailName <> "Master" Then
docDisplayName = (Left(docFile.DisplayName, Len(docFile.DisplayName) - Len(docFile.LevelOfDetailName) - 3))
'MessageBox.Show( (Left(docFile.DisplayName, Len(docFile.DisplayName) - Len(docFile.LevelOfDetailName) - 3)) ,"")
Else
docDisplayName = docFile.DisplayName
'MessageBox.Show(docFile.DisplayName,"")
End If
If iProperties.Value(docDisplayname, "Project", "Authority") <> "Assembly" Then
iProperties.Value( docDisplayName, "Project", "Authority") = "Assembly"
End If
End If
End If
Next
Else
MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If
'''Created By: Mega Jerk. - Featuring Non-Commented Code By: Mega Jerk. (Thanks ya big jerk!)
If my solution worked or helped you out, please don't forget to hit the kudos button 🙂iLogicCode Injector:
goo.gl/uTT1IB