Message 1 of 4
Parts List Column Fitting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been using this handy little code (from this forum) for condensing column widths of my various parts lists in my 10-sheet drawing. Code works great as it updates all 10 sheets at one time, but I'm looking to modify the code as to where it will do the column update on the current sheet (of the 10) I'm working on.
I'm not super skilled at iLogic so I'm not sure which command(s) I would need to change to accomplish the single sheet column update. Suggestions welcomed!
Sub Main() If Not ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then MessageBox.Show("Hey the rule only runs in drawing documents!") Exit Sub End If Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oSheet As Sheet 'Create sheet counter variable Dim iSheetCount As Integer iSheetCount = 0 Dim oProgressBar As Inventor.ProgressBar 'Progress bar oMessage = "Organizing All Parts List" Dim SheetCount As Integer SheetCount = oDrawDoc.Sheets.Count oProgressBar = ThisApplication.CreateProgressBar(False, SheetCount, oMessage, True) 'True = Cancel button For Each oSheet In oDrawDoc.Sheets For Each oPL As PartsList In oSheet.PartsLists 'Get the current sheet number iSheetCount = iSheetCount + 1 'Update the progress bar to reflect which sheet is being operated on oProgressBar.Message = ("Processing Sheet " & iSheetCount & " of " & SheetCount & "...") oProgressBar.UpdateProgress 'Sort Parts List By: oPL.Sort("PART #") oPL.Renumber 'Call Sub PartsListFitColumns(oPL) Next Next oProgressBar.Close End Sub 'Fit columns of parts list Public Function PartsListFitColumns(oPartsList As PartsList) As PartsList If oPartsList Is Nothing Then Exit Function ' get font info Dim dWidth As Double dWidth = oPartsList.DataTextStyle.FontSize * oPartsList.DataTextStyle.WidthScale ' find longest string in each column and resize column Dim oRow As PartsListRow Dim sData As String Dim iCol As Integer Dim iCols As Integer iCols = oPartsList.PartsListColumns.Count ' Set up array To hold column widths Dim iLen() As Integer ReDim iLen(iCols) ' initialize to header lengths For iCol = 1 To iCols iLen(iCol) = Len(oPartsList.PartsListColumns(iCol).Title) For Each oRow In oPartsList.PartsListRows If oRow.Visible = True Then sData = oRow.Item(iCol).Value ' get the data from the cell If Len(sData) > iLen(iCol) Then iLen(iCol) = Len(sData) End If End If Next oRow Dim col_l As Double = oPartsList.PartsListColumns(iCol).Width Dim desired_col_l = dWidth * (iLen(iCol) + 2) Dim ratio1 As Double = 0.85 Dim ratio2 As Double = 0.8 Dim ratio3 As Double = 0.75 Dim ratio4 As Double = 0.7 Dim ratio5 As Double = 0.62 'messagebox.Show(iLen(iCol)) Select Case iLen(iCol) Case <= 10 If col_l <> desired_col_l * ratio1 Then oPartsList.PartsListColumns(iCol).Width = desired_col_l * ratio1 End If Case 11 To 20 If col_l <> desired_col_l * ratio2 Then oPartsList.PartsListColumns(iCol).Width = desired_col_l * ratio2 End If Case 21 To 30 If col_l <> desired_col_l * ratio3 Then oPartsList.PartsListColumns(iCol).Width = desired_col_l * ratio3 End If Case 31 To 40 If col_l <> desired_col_l * ratio4 Then oPartsList.PartsListColumns(iCol).Width = desired_col_l * ratio4 End If Case >= 41 If col_l <> desired_col_l * ratio5 Then oPartsList.PartsListColumns(iCol).Width = desired_col_l * ratio5 End If End Select Next iCol Return oPartsList End Function