Hi Alan
I'm working on this once again,
I've started with a basic approach, the idea is to run from the main assembly, and sequentially number all parts until it hits the frame, then run a sub routine to identify which members are unique and calculate quantities for all parts. At some point I need to work out how to tell the program what the final part number was used in the frame so that the program can carry on from there but not super worried about that now.
I've identified the key parameters I'm going to work with for now are;
Section, Length, Material, Mass, Area, Volume, COGX, COGY & COGZ with most of these properties being drawn from the physical tab of the iproperties for each part.
Just for right now, I'm running a test that tries to read the value and write it into a custom "test" variable in each part so I can check I'm getting the information to start, and it looks like I'm getting nothing, I'm also not entirely sure how to get these variables like this, its a little different to the other examples I've found, If you able to point me in the right direction it would be much appreciated
Kind Regards
Roydon Mackay
Sub Main
'Reference to the Assembly Document
Dim Doc As AssemblyDocument = ThisApplication.ActiveDocument
'Reference to the BOM
Dim BOM As BOM = Doc.ComponentDefinition.BOM
BOM.PartsOnlyViewEnabled = True
'Enable Structured View
Dim BomView As BOMView = BOM.BOMViews.Item("Parts Only")
'Create the Assembly Counter Number
'Dim Gen_Assembly_No As String = Doc.ComponentDefinition.PropertySets.Item(2).Item("PART NUMBER")
''Set the General Assembly Number as GEN-001 *To be changed later
'Gen_Assembly_No = ("001")
SetPartNumbering (BomView.BOMRows, 001)
End Sub
Private Sub SetPartNumbering (BOMRows As BOMRowsEnumerator, Assembly_No As String)
'Iterate through the contents of the BOM Row's
Dim Part_Counter As String = 001
For i As Integer = 1 To BOMRows.Count
'Get the Current Row
Dim Row As BOMRow = BOMRows.Item(i)
'Determine if the Bom Row is the Inventor Frame Assembly, if so start the subroutine to work through that sub assembly
If Not Row.ChildRows Is Nothing Then
SetFrameGenPartNos(Row.ChildRows, 001)
'If the item is a standard part, give it the next part number in the sequence
End If
Next
End Sub
Private Sub SetFrameGenPartNos(BOMRows As BOMRowsEnumerator, Start_Number As String)
'Iterate through all rows of the frame
For i As Integer = 1 To BOMRows.Count
'Get the Current Row
Dim Row As BOMRow = BOMRows.Item(i)
'Reference the primary ComponentDefinition of the Row
Dim Compdef As ComponentDefinition = Row.ComponentDefinitions.Item(1)
'Get the key component properties from each part
'Dim Section As String = Compdef.Document.Item(2).Item("STOCK NUMBER")
Dim Length As Single = Compdef.Document.PropertySets.Item(4).Item(G_L).Value
'Dim Material As String = Compdef.Document.Item(7).Item("MATERIAL")
'Dim Mass As Single = Compdef.Document.Item(7).Item("MASS")
'Dim Area As Double = Compdef.Document.Item(7).Item("AREA")
'Dim Volume As Double = Compdef.Document.Item(7).Item("VOLUME")
'Dim COGX As Double = Compdef.Document.Item(7).Item("X")
'Dim COGY As Double = Compdef.Document.Item(7) Item("Y")
'Dim COGZ As Double = Compdef.Document.Item(7) Item("Z")
'Confirm that the values are being read from each part, write the value to a custom propert 'test'
Try
Dim TEST As [Property] = Compdef.Document.PropertySets.Item(4).Item("TEST")
TEST.Value = Length
Catch
Compdef.Document.PropertySets.Item(4).Add(Row.ItemQuantity, "TEST")
End Try
Next
End Sub