OK. I wasn't sure why you were checking for the same letter ("S") twice in your filter loop, so I changed the second "S" to "BOF", because that's what you previously said was in that sort order position, and I assumed it was literally the first 3 letters of the part number. I also simplified the part where it checks the first 1 or 3 characters of the part number. Then I changed the 1's in your Sort line to True, because that method is expecting Boolean type values, and True is easier to read/understand than 1. Then after the sort, renumber, and save overrides, I included a simple loop to get the "CATEGORY" column, and remove it.
Here's the code:
Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
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 = ThisApplication.ActiveDocument
Dim oPList As PartsList = oDDoc.ActiveSheet.PartsLists(1)
'Sort order (by what the Part Number value starts with)
'C,K,S,M,A,BOF,B#
Dim oPN As String
Dim oType As PartsListCell
For i As Integer = 1 To oPList.PartsListRows.Count
'Get value from PartNumber column
oPN = oPList.PartsListRows.Item(i).Item("PART NUMBER").Value
oType = oPList.PartsListRows.Item(i).Item("CATEGORY")
If oPN.StartsWith("C") Then
oType.Value = "1"
ElseIf oPN.StartsWith("K") Then
oType.Value = "2"
Else If oPN.StartsWith("S") Then
oType.Value = "3"
Else If oPN.StartsWith("M") Then
oType.Value = "4"
Else If oPN.StartsWith("A") Then
oType.Value = "5"
Else If oPN.StartsWith("BOF") Then
oType.Value = "6"
Else
oType.Value = "7"
End If
Next
oPList.Sort("CATEGORY", True, "PART NUMBER", True)
oPList.Renumber
oPList.SaveItemOverridesToBOM
'get the 'CATEGORY' column, and remove it
For Each oCatCol As PartsListColumn In oPList.PartsListColumns
If oCatCol.Title = "CATEGORY" Then
oCatCol.Remove
End If
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

(Not an Autodesk Employee)