My understanding is that you have an assembly and you want to create drawings for each individual part?
If so below is code that I frankensteined together and modified to fit my purposes, I believe you will be able to use it as well. If you have any questions about it feel free to ask.
Sub Main()
'If the assembly is declared as a Component assignment of Item # and QTY. is unnecessary
If iProperties.Value("Summary", "Subject") = "Component" Then
Else
'Reference Assembly Document
Dim oAssemblyDocument As AssemblyDocument
oAssemblyDocument = ThisDoc.Document
'Reference each instance of a model in the assembly
Dim oAssemblyComponentDefinition As AssemblyComponentDefinition
oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition
'Reference the Bill Of Materials
Dim oBOM As BOM
oBOM = oAssemblyComponentDefinition.BOM
'Call for Structured View
oBOM.StructuredViewEnabled = True
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews(2) 'Structured view
'Only change the Top Level of the Model Tree models
'models within sub-assemblies are ignored.
oBOM.StructuredViewFirstLevelOnly = True
oBOM.StructuredViewDelimiter = "."
'Call sub-programs
Call RecursiveCheckAndSetProps(oBOMView.BOMRows)
Call UpdateParts()
End If
End Sub
Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator)
'Loop for each unique model in the assembly
For Each oBOMRow As BOMRow In oRowsElements
'Reference property of models within assembly
Dim oComponentDefinition As ComponentDefinition
oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)
'Reference variables to BOM Item # and QTY.
Dim oBOMItemNumber As String
Dim oBOMItemQuantity As String
oBOMItemQuantity = oBOMRow.ItemQuantity() 'this is item quantity in the BOM
oBOMItemNumber = oBOMRow.ItemNumber() 'this is item number in the BOM
For i = 1 To oBOMRow.ComponentDefinitions.Count
Dim oComponentDefinitionPropertySet As PropertySet
oComponentDefinitionPropertySet = oBOMRow.ComponentDefinitions(i).Document.PropertySets.Item(4)
oComponentDefinition = oBOMRow.ComponentDefinitions.Item(i)
oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Inventor User Defined Properties")
'Check to see if model has had BOM Item # set, if so skip editing model iProperties
Try
prop = oComponentDefinitionPropertySet.Item("BOM Number")
Catch
'Add BOM Item # and QTY. as Custom iProperties
Try
oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number")
oComponentDefinitionPropertySet.Add(oBOMItemQuantity, "BOM QTY")
Catch
oComponentDefinitionPropertySet.Item("BOM Number").Value = oBOMItemNumber
oComponentDefinitionPropertySet.Item("BOM QTY").Value = oBOMItemQuantity
End Try
End Try
Logger.Info(oBOMRow.ComponentDefinitions(i).Document.DisplayName & " - " & oBOMItemNumber)
Next
Next
End Sub
Sub UpdateParts()
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim aDoc As DocumentsEnumerator = oDoc.AllReferencedDocuments
Dim iDoc As Document
For Each iDoc In aDoc
'Here we set iProperties in each of the parts in assembly
Dim sTS As String = iDoc.FullFileName
Dim FNamePos As Long = InStrRev(sTS, "\", - 1)
Dim docFName As String = Mid(sTS, FNamePos + 1, Len(sTS) -FNamePos)
'Add BOM Item # & QTY. to iProperty Fields Company and Manager respectively
If iProperties.Value(docFName, "Custom", "BOM Number") = "" Then
Else
iProperties.Value(docFName, "Summary", "Manager") = iProperties.Value(docFName, "Custom", "BOM QTY")
iProperties.Value(docFName, "Summary", "Company") = iProperties.Value(docFName, "Custom", "BOM Number")
End If
Next
End Sub