@cadman777, @A.Acheson
I'm not a C#.net programmer either, but I can sometimes understand it, because it is a close native to vb.net, which iLogic uses. In C#, they state the variable's Type just before the variable's name/placeholder. They also enclose the single or multiple lines of content within a block of code (after the initial opener line) within the "{" and "}" symbols. This is why you don't see any "End If" or "Next" statements. Yes, is some different functionality to, but simpler stuff is often not too terribly hart to translate.
I believe I understand the code that @Lesoux posted, and have created an iLogic (vb.net) version of it, and have tested it. In the few tests I have put it through, it seems to work just fine, and quickly too. I believe his code was meant to be its own standalone Sub, which could be referenced to do this as a side task, and meant to be the entire code. This is because it is set up to receive the PartsList object as an input variable, instead of directly retrieving it from the active drawing document. So to simplify, I left a commented out starter line that one might use for that similar purpose, but am using the "Sub Main" opener that most iLogic users are used to.
If you would like to use this as a reference Sub, as it was designed:
- Un-comment the Public Sub line (may have to get rid of the 'Public' part, depending on how you are using it), then comment out the Sub Main line.
- Get rid of all the code from after the Sub opener, to (and including) the For Each oPList line.
I added the document type check, getting the drawing document, and the two loops (each Sheet & each PartsList). I also changed a few variable names to shorten them.
Here's my iLogic version of @Lesoux 's C# code:
'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
Next
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' 👍.
Wesley Crihfield

(Not an Autodesk Employee)