auto fit columns in parts list

auto fit columns in parts list

cadman777
Advisor Advisor
5,995 Views
56 Replies
Message 1 of 57

auto fit columns in parts list

cadman777
Advisor
Advisor

Hello All,

I just got through searching this forum for some code that 'auto fits columns in the drawing parts list'.

I found 2 threads, but they're very old and don't have what I need.

Does anybody have any code they can share w/me?
My idea, based on what I found, is to count all the characters in all the lines in each column, then widen that column by the longest string + whatever additional characters the user specifies in the code.

Does that sound like it's reasonable and do-able?

Thanx ...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Accepted solutions (1)
5,996 Views
56 Replies
Replies (56)
Message 41 of 57

WCrihfield
Mentor
Mentor

That adjustment was too much for me, because it causes it squished some columns further than they are allowed, and caused the contents of some cells to wrap to a new row.

However, we are definitely on the right track.

I made one more tweak to the math in that line, and now the results seem as perfect as I've ever seen them, at least for my test application.

I changed that line to this:

oPList.PartsListColumns(oNext).Width = oWidths(i)  + (oPList.DataTextStyle.FontSize * .5)

after making this change, and running the code on my drawing, I zoomed in extremely close on my PartsList to inspect it.  I can't manually move the column dividers ANY towards narrowing them further, and none of the rows contents were or titles were wrapped to new rows.

Ladies and gentlement...I think we have a winner here!

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 42 of 57

WCrihfield
Mentor
Mentor

That adjustment was too much for me.  It caused some of my columns to squish to narrow (further than you can manually narrow them), and caused some of the row's contents to wrap to new rows.

However we are definitely on the right track here.

I made another adjustment to the math in this line, that seems to work perfectly now.

I changed that line to this:

 

oPList.PartsListColumns(oNext).Width = oWidths(i)  + (oPList.DataTextStyle.FontSize * .5)

 

After making this change in the code and running on my text drawing, I zoomed way in as far as I could on my PartsList, to inspect it.  I couldn't manually drag the dividers between the columns ANY towards narrowing them, and none of the cell contents were wrapped to new rows.

Ladies and gentlement...I believe we have a winner here!

 

PS:  Sorry it posted twice.  When I posted the first time it said it errored out and I didn't see the post.  Then two showed up.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 43 of 57

WCrihfield
Mentor
Mentor

In my test assembly drawing, I am using the following settings in my TextStyle:

(all numbers in these settings are in Inches)

Arial .100 TextStyle settings.png

 

And I am using the following PartsListStyle settings:

 

PartsListStyle settings.png

 

Then I manually adjusted all column widths to way wider than they needed to be, just for the test.

And here is the updated iLogic rule (based on @Lesoux c# code, kudos):

 

 

'Public Sub FitColumnsWidth(oPartsList As PartsList)
Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDrawing.Document
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	For Each oSheet As Inventor.Sheet In oDDoc.Sheets
		For Each oPList As PartsList In oSheet.PartsLists
			Dim oPPoint As Point2d = oTG.CreatePoint2d(0,0)
			Dim oTempGNote As Inventor.GeneralNote = oSheet.DrawingNotes.GeneralNotes.AddFitted(oPPoint, "", oPList.DataTextStyle)
			Dim oColQty As Integer = oPList.PartsListColumns.Count
			Dim oWidths(oColQty) As Double
			Dim i As Integer
			For i = 0 To oColQty - 1
				Dim oNext As Integer = i + 1
				oTempGNote.Text = oPList.PartsListColumns(oNext).Title
				oWidths(i) = oTempGNote.FittedTextWidth
				For Each oRow As PartsListRow In oPList.PartsListRows
					If oRow.Visible Then
						oTempGNote.Text = oRow(oNext).Value
						If oTempGNote.FittedTextWidth > oWidths(i) Then
							oWidths(i) = oTempGNote.FittedTextWidth
						End If
					End If
				Next
				oPList.PartsListColumns(oNext).Width = oWidths(i)  + (oPList.DataTextStyle.FontSize * .5)
			Next
			oTempGNote.Delete()
		Next
	Next
End Sub

 

 

     When I ran this rule, it seemed to work exactly as I wanted it to.  It narrowed all of the PartsList columns, seemingly the maximum amount, without causing them to squish too narrow, and without causing the contents of any of the cells to wrap to new lines/rows.  Even after zooming in as far as possible on the end of the column divider, and attempting to manually adjust that divider to narrow the column, it wouldn't go ANY narrower.

     Then I tested manually narrowing one of my columns, so that some of the cell contents within wrapped to new rows, then ran the rule.  It corrected the column width, so that the contents of that row no longer wrap to a new row, just as I was hoping for.

     Now, this may not be an ideal solution for the situations where you need your content to wrap to new rows, in order to fit the PartsList within a certain available width, or need to maintain a maximum width.  In that situation, you may need to either add some additional code which sets your limitations, then checks and adjusts the outcome accordingly, or you may need to use a different technique.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 44 of 57

Darius_CAD
Enthusiast
Enthusiast

Hi,

 

Can you help me?

With this code I have error: all other Sub's or Function's must be after Sub Main()

 

Inventor 2017; iLogic

 

Thank you.

0 Likes
Message 45 of 57

A.Acheson
Mentor
Mentor

Hi,Can you help me?

With this code I have error: all other Sub's or Function's must be after Sub Main()

Inventor 2017; iLogic

........................................

Your post was hard to find it got stuck in the middle of 44 messages.

 

Sub main is the driving sub with the calls to further subs/function  contained within.

 

What code are you looking to use?

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 46 of 57

Darius_CAD
Enthusiast
Enthusiast

There is code:

 

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)
Next iCol

' loop thru each row
For Each oRow In oPartsList.PartsListRows
	If oRow.Visible = True Then
		For iCol = 1 To iCols
			sData = oRow.Item(iCol).Value ' get the data from the cell
			
			If Len(sData) > iLen(iCol) Then
				iLen(iCol) = Len(sData)
			End If
		Next iCol
	End If
Next oRow

' resize the columns (note add extra 2 character width for padding)
For iCol = 1 To iCols
	oPartsList.PartsListColumns(iCol).Width = dWidth * (iLen(iCol) + 2) / 1.3
Next iCol

Return oPartsList

End Function
0 Likes
Message 47 of 57

WCrihfield
Mentor
Mentor

It looks like the code you posted is set-up to be a reference function, not the main/overall code.  So the intent is to have a Sub Main...some other code, a call to this reference function, some more code...then End Sub, then this reference function would be its own block of code somewhere below End Sub.  The call within the Sub Main...End Sub block of code would be calling this function below to run at that point.

 

If you want this code to act as a complete standalone rule, you would have to change a few things.

Replace this:

Public Function PartsListFitColumns(oPartsList As PartsList) As PartsList

with this:

Sub Main

Then, since the old code was being provided with a PartsList as an input variable, we would now have to get the PartsList a different way.  There are multiple ways to get a PartsList, so I'm just going to show one simple way as an example.  Put this as the next line under your Sub Main, and before your "If oPartsList Is Nothing" check line.

Dim oPartsList As PartsList = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingPartsListFilter,"Select a Parts List.")

Now at the end of the rule, delete the line "Return oPartsList", then simply replace "End Function" with "End Sub" (without the quotes).

That should convert your code to a standalone iLogic rule that should work by itself.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 48 of 57

Darius_CAD
Enthusiast
Enthusiast

Thank you! It works. I hided "If oPartsList Is Nothing.."

 

Sub Main '2021 changed

Dim oPartsList As PartsList = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingPartsListFilter,"Select a Parts List.") ' 2021 add

'If oPartsList Is Nothing Then Exit Function '2021 hide

' 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)
Next iCol

' loop thru each row
For Each oRow In oPartsList.PartsListRows
If oRow.Visible = True Then
For iCol = 1 To iCols
sData = oRow.Item(iCol).Value ' get the data from the cell

If Len(sData) > iLen(iCol) Then
iLen(iCol) = Len(sData)
End If
Next iCol
End If
Next oRow

' resize the columns (note add extra 2 character width for padding)
For iCol = 1 To iCols
oPartsList.PartsListColumns(iCol).Width = dWidth * (iLen(iCol) + 2) / 1.8
Next iCol

End Sub '2021 changed

 

 

0 Likes
Message 49 of 57

WCrihfield
Mentor
Mentor

Not exactly on topic, but related, and useful.

Using the same techniques as I did for adjusting the columns widths of a PartsList earlier in this post, I have developed another iLogic rule to do the same thing for a RevisionTable.  So this other rule will widen/narrow each column within all RevisionTables on all sheets of a drawing, to a width that best fits the contents of all cell in their column.  It finds the longest text within the column, then sets the column width to match it, which also causes any rows which were wrapping to new lines to fit cell contents, to just use one line (and fix the row height to single row height).

Here is the link to that contribution post.


If this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 50 of 57

WCrihfield
Mentor
Mentor

Since I wanted a 1-click way to use this tool, I created a VBA macro out of it.  I had to change the oWidths variable's type from an Array (which had it's size pre-set), to an ArrayList, because VBA didn't like using a variable to set the initial size of the Array, and I didn't want to deal with using ReDim.  In order to use the ArrayList, I had to go to Tools > References, then Browse to set a reference to "mscorlib.dll" (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.tlb") so VBA would recognize it.

This is the VBA macro version of the iLogic code I posted here back on 01-15-2021 07:31 AM.

Sub PartsList_AutoFitWidth()
    If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
        Call MsgBox("A Drawing Document must be active for this rule to work. Exiting.", vbOKOnly + vbCritical, "WRONG DOCUMENT TYPE")
        Exit Sub
    End If
    Dim oDDoc As DrawingDocument
    Set oDDoc = ThisApplication.ActiveDocument
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
    Dim oSheet As Inventor.Sheet
    Dim oPList As PartsList
    For Each oSheet In oDDoc.Sheets
        For Each oPList In oSheet.PartsLists
            Dim oPPoint As Point2d
            Set oPPoint = oTG.CreatePoint2d(0, 0)
            Dim oTempGNote As Inventor.GeneralNote
            Set oTempGNote = oSheet.DrawingNotes.GeneralNotes.AddFitted(oPPoint, "", oPList.DataTextStyle)
            Dim oColQty As Integer
            oColQty = oPList.PartsListColumns.Count
            Dim oWidths As New ArrayList
            Dim i As Integer
            For i = 0 To oColQty - 1
                Dim oNext As Integer
                oNext = i + 1
                oTempGNote.Text = oPList.PartsListColumns(oNext).Title
                Call oWidths.Insert(i, oTempGNote.FittedTextWidth)
                Dim oRow As PartsListRow
                For Each oRow In oPList.PartsListRows
                    If oRow.Visible Then
                        oTempGNote.Text = oRow(oNext).Value
                        If oTempGNote.FittedTextWidth > oWidths.Item(i) Then
                            oWidths.Item(i) = oTempGNote.FittedTextWidth
                        End If
                    End If
                Next
                oPList.PartsListColumns(oNext).Width = oWidths.Item(i) + (oPList.DataTextStyle.FontSize * 0.5)
            Next
            Call oTempGNote.Delete
        Next
    Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 51 of 57

emanuel.c
Collaborator
Collaborator

Hi @WCrihfield, thank you for the code! I know this was a while ago, but the code here doesn't work well for me. You wouldn't know the reason? I tried your font settings too, with no success. Here's a snapshot of just after running the code, for an example:

 

emanuelc_0-1685724162819.png

 

 

0 Likes
Message 52 of 57

WCrihfield
Mentor
Mentor

Hi @emanuel.c.  I am not 100% sure what may be causing that behavior, because I have been using that code ever since the date it was posted above without encountering that.  After reviewing the code again just now, it looks like the only 'raw' numerical value involved is in line 28 of my iLogic version above, or line 36 of the VBA version above, where I am specifying the value '.5'.  I'm wandering if there may be a Double data type tolerance/accuracy related issue going on there.  Maybe that value needs to have a bunch of zero's after it to improve its accuracy.  I believe the accuracy of the Double data type goes all the way down to the 15th decimal place, when there is only a zero to the left of the decimal point.  But that is just a wild guess, without any testing to back it up.  I know I have seen other ways of attaining super accurate text size before, that may work better than how it is being done here, but I don't recall where my notes/snippet are about that process.  I think they included AddReference &/or Imports to other areas of the vb.net system, to use some other types of tools, like along the System.Drawing.Font direction.  Following are some links to content on Microsoft's vb.net website that may point you in the right direction for now.

https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/using-fonts-and-text?view=netfram... 

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics.drawstring?view=dotnet-plat-ext... 

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.textrenderer.drawtext?view=windows... 

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.textrenderer.measuretext?view=wind... 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 53 of 57

emanuel.c
Collaborator
Collaborator

Thank you! For now, I went back to something like this - as posted above. It doesn't fit columns 100% but it's fairly close.

 

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 NUMBER")
			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
0 Likes
Message 54 of 57

ZdenkoSantic
Contributor
Contributor

Try this one

Sub Main()
	If Not ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
		MessageBox.Show("Can only run rule on drawing documents.")
		Exit Sub
	End If
	
	Dim oDrawDoc As DrawingDocument
	oDrawDoc = ThisApplication.ActiveDocument
	
	Dim oSheet As Sheet
	oSheet = oDrawDoc.Sheets.Item(1)
	
'	For Each oPL As PartsList In oSheet.partslists
		
'	Next
	
	Dim oSelectSet As SelectSet
	oSelectSet = oDrawDoc.SelectSet
	
	If oSelectSet.Count = 0 Then Exit Sub
	If oSelectSet.Item(1).Type <> kPartsListObject Then Exit Sub
		
	Dim oPartslist As PartsList
	oPartslist = oSelectSet.Item(1)
	'oPartslist = oSheet.PartsLists.Item(1)
	PartsListFitColumns(oPartslist)
	
End Sub

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)
	Next iCol

	' loop thru each row
	For Each oRow In oPartsList.PartsListRows
		If oRow.Visible = True Then
			For iCol = 1 To iCols
				sData = oRow.Item(iCol).Value ' get the data from the cell
				
				If Len(sData) > iLen(iCol) Then
					iLen(iCol) = Len(sData)
				End If
			Next iCol
		End If
	Next oRow

	' resize the columns (note add extra 2 character width for padding)
	For iCol = 1 To iCols
		oPartsList.PartsListColumns(iCol).Width = dWidth * (iLen(iCol) + 2) / 1.3
	Next iCol

	Return oPartsList
End Function
0 Likes
Message 55 of 57

emanuel.c
Collaborator
Collaborator

Yes @ZdenkoSantic it works well, but I prefer mine I posted above. The ratios for wider columns seem to work better.

0 Likes
Message 56 of 57

madstrolle
Enthusiast
Enthusiast

Hi,

This code resizes the columns and let you type in a specific total length of the partlist.

In this line you specify your desired length: 

 

PartsListFitColumnsAndResize(oPL, 100.0) ' 100.0 is the desired length (in millimeters) 

 

Code:

 

Sub Main()
If Not ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
MessageBox.Show("Can only run rule on drawing documents.")
Exit Sub
End If
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
For Each oSheet In oDrawDoc.Sheets
For Each oPL As PartsList In oSheet.PartsLists
PartsListFitColumnsAndResize(oPL, 100.0) ' 100.0 is the desired length (in millimeters)
Next
Next
End Sub

Public Function PartsListFitColumnsAndResize(oPartsList As PartsList, desiredLength As Double) 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
Next iCol
' Calculate the total width of the part list
Dim totalWidth As Double
For iCol = 1 To iCols
totalWidth += dWidth * (iLen(iCol) + 2) / 1.3
Next iCol
' Calculate the scaling factor for the desired length
Dim scale As Double
If totalWidth <> 0.0 Then
scale = desiredLength / totalWidth
Else
scale = 1.0
End If
' Set the new column widths based on the scaling factor
For iCol = 1 To iCols
oPartsList.PartsListColumns(iCol).Width = dWidth * (iLen(iCol) + 2) * scale / 1.3
Next iCol
Return oPartsList
End Function

Message 57 of 57

morgan_weiderydR27EU
Explorer
Explorer

Hi.

I am looking to make the part list into a single row if the row would be a double row. I would also like to keep the total width of the part list the same. I have tried with most of the functions posted here and some have worked quite well. The only thing i am missing is about keeping the total width.

Also, is it possible to put this function into your drawing template file so that this will work for all my coworkers automatically?

0 Likes