Adding Total Mass to the Parts List
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I've got a working Ilogic code here that will read the title of the active document and the weight and add it to the existing parts list.
It works well for a drawing that has its main parts list on the first sheet.
Working Code:
oDocument = ThisDoc.Document Try 'look for the first parts list on the drawing Dim oPartsList As PartsList oPartsList = oDocument.ActiveSheet.PartsLists.Item(1) oPartsList.Title = "B.O.M. / " & iProperties.Value("Custom", "TITLE I") &" / "&iProperties.Value("Project", "Part Number") &"-"&ActiveSheet.Size Dim oPLCol As Inventor.PartsListColumn Dim currIndex As Integer Dim weightColumnIndex As Integer currIndex = 1 For Each oPLCol In oPartsList.PartsListColumns If Trim(UCase(oPLCol.Title)) = Trim(UCase("QTY. WT.")) Then weightColumnIndex = currIndex End If currIndex = currIndex + 1 Next Dim chkItemNoCell As Inventor.PartsListCell Dim newRow As Inventor.PartsListRow newRow = oPartslist.PartsListRows.Add(oPartslist.PartsListRows.Count, False) newRow.Height = myRowHeight 'Remove any existing TOTAL lines Dim chkTotCell As Inventor.PartsListCell For Each PLRow In oPartslist.PartsListRows If PLRow.Visible Then chkTotCell = PLRow.Item(1) If chkTotCell.Value = "TOTAL" Then PLRow.Remove End If End If Next myCell = newRow.Item(1) myCell.Value = "TOTAL" myCell = newRow.Item(weightColumnIndex) 'Define the open document Dim openDoc As Document openDoc = ThisDoc.Document 'Look at the model file referenced in the open document Dim docFile As Document docFile = ThisDoc.ModelDocument 'format model file name Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) Dim docFName As String docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 'Reads mass value from part file kgmass = iProperties.Mass(docFName) 'Converts mass value to LB mass = kgmass * 2.20462 'Writes Value of Mass to Parts List myCell.Value = mass Catch 'inform user no parts list was found MessageBox.Show("No Parts List Found", "iLogic") End Try 'Forces Inventor to update InventorVb.DocumentUpdate()
So now I am trying to expand this ilogic rule to accomplish a few more things.
1. It will loop through all sheets of a drawing looking for the parts list.
2. If it finds a parts list it will update the title of the parts list to show which assembly it came from .
3. It will update the total mass of the parts list with that of the referneced assembly.
Currently the title and the mass are incorrect as it keeps referencing back to the active document and not the assembly each parts list is made from.
I was able to enclose it in a for loop for the number of sheets and get it to loop through all sheets in a drawing set.
Edited code with looping:
Sub Main() oDocument = ThisDoc.Document Dim oDrawingDoc as Inventor.DrawingDocument oDrawingDoc = ThisApplication.ActiveDocument 'Cycle Through all Sheets For SheetNumber = 1 To oDrawingDoc.Sheets.Count oDrawingDoc.Sheets(SheetNumber).Activate Try 'look for the first parts list on the drawing Dim oPartsList As PartsList 'Need to loop through each sheet looking for parts list oPartsList = oDocument.ActiveSheet.PartsLists.Item(1) 'Need to refernece the title of the part or assembly not the drawing file oPartsList.Title = "Parts List : " &iProperties.Value("Project", "Part Number") Dim oPLCol As Inventor.PartsListColumn Dim currIndex As Integer Dim weightColumnIndex As Integer currIndex = 1 For Each oPLCol In oPartsList.PartsListColumns 'Parts List must have a column called QTY. WT. for the code to run. Or adjust weight column name to match what the code is looking for. If Trim(UCase(oPLCol.Title)) = Trim(UCase("QTY MASS")) Then weightColumnIndex = currIndex End If currIndex = currIndex + 1 Next Dim chkItemNoCell As Inventor.PartsListCell Dim newRow As Inventor.PartsListRow newRow = oPartslist.PartsListRows.Add(oPartslist.PartsListRows.Count, False) newRow.Height = myRowHeight 'Remove any existing TOTAL lines Dim chkTotCell As Inventor.PartsListCell For Each PLRow In oPartslist.PartsListRows If PLRow.Visible Then chkTotCell = PLRow.Item(1) If chkTotCell.Value = "TOTAL" Then PLRow.Remove End If End If Next myCell = newRow.Item(1) myCell.Value = "TOTAL" myCell = newRow.Item(weightColumnIndex) 'Define the open document Dim openDoc As Document openDoc = ThisDoc.Document 'Look at the model file referenced in the open document Dim docFile As Document docFile = ThisDoc.ModelDocument 'format model file name Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) Dim docFName As String docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 'Reads mass value from part file kgmass = iProperties.Mass(docFName) 'Converts mass value to LB mass = kgmass * 2.20462 'Writes Value of Mass to Parts List myCell.Value = mass Catch 'inform user no parts list was found MessageBox.Show("No Parts List Found", "iLogic") End Try Next 'Forces Inventor to update InventorVb.DocumentUpdate() End Sub
I know its a long post, Sorry.
Summary. How do you refernece the the assembly a parts list comes from?