Hi @Ahmed.shawkyXTZHN
I gave you code to handle assemblies with subassemblies in your other thread:
https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/holes-counting-and-reflecting-the-resul...
When it comes to the table on the drawing there's no simple way to keep the table synced with the properties. Maybe create a table as sketched symbol, but we dont really know which properties will exist beforehand so it's difficult to make that generic. You could also try to push the properties to excel and then reference the excelsheet from the table. I think this static table is your best option in this case though.
Maybe you don't have a layer called "0" in your drawing template and that's why it didn't work. I removed that line for you in the code now:
Dim oDrawing As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDrawing.ActiveSheet
Dim oHoles As New List(Of KeyValuePair(Of String, Integer))
Dim oPunches As New List(Of KeyValuePair(Of String, Integer))
Dim oAsm As AssemblyDocument = oSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
Dim oCustomProps As PropertySet = oAsm.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
For Each oProp As Inventor.Property In oCustomProps
If oProp.Name.StartsWith("Hole: ") Then
oHoles.Add(New KeyValuePair(Of String, Integer)(oProp.Name.Replace("Hole: ", ""), oProp.Value))
ElseIf oProp.Name.StartsWith("Punch: ") Then
oPunches.Add(New KeyValuePair(Of String, Integer)(oProp.Name.Replace("Punch: ", ""), oProp.Value))
End If
Next
Dim oHoleTable As CustomTable
Dim oPunchTable As CustomTable
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
If oHoles.Count > 0
Dim colTitles(1) As String
colTitles(0) = "Diameter"
colTitles(1) = "Number"
oHoleTable = oSheet.CustomTables.Add("Holes", oTG.CreatePoint2d(10, 10), 2, oHoles.Count, colTitles)
oHoleTable.Columns.Item(1).ValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
For i = 1 To oHoles.Count
oHoleTable.Rows(i).Item("Diameter").Value = oHoles(i - 1).Key
oHoleTable.Rows(i).Item("Number").Value = oHoles(i - 1).Value
Next
End If
If oPunches.Count > 0
Dim colTitles(1) As String
colTitles(0) = "Name"
colTitles(1) = "Number"
oPunchTable = oSheet.CustomTables.Add("Punches", oTG.CreatePoint2d(If (oHoleTable Is Nothing, 10, 10 + oHoleTable.RangeBox.MaxPoint.X - oHoleTable.RangeBox.MinPoint.X) _
, 10), 2, oPunches.Count, colTitles)
oPunchTable.Columns.Item(1).ValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
For i = 1 To oPunches.Count
oPunchTable.Rows(i).Item("Name").Value = oPunches(i - 1).Key
oPunchTable.Rows(i).Item("Number").Value = oPunches(i - 1).Value
Next
End If
Make sure the active sheets first drawing view is referencing your assembly when you run this rule. Also make sure to run the rule to populate the iproperties in your assembly before running this rule in the drawing. Then it should work. Let me know if there are any problems 🙂