iLogic code for sorting Parts list by the Part Number letter

iLogic code for sorting Parts list by the Part Number letter

stuart_dean
Explorer Explorer
1,492 Views
5 Replies
Message 1 of 6

iLogic code for sorting Parts list by the Part Number letter

stuart_dean
Explorer
Explorer

I would like a iLogic rule to sort our parts list is a specific order. The order is, part numbers beginning with C, then K, then S, then M, then A, then BOF, then B#. Is anybody able to help please?  

0 Likes
1,493 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

I don't think it is going to be possible right now.  It only allows you to specify column priority when sorting, then standard alphanumeric ascending or descending for each column, as how to sort its contents.  There isn't currently an iLogic method exposed for the PartsList object that would allow for super custom rearranging scenarios.   The assembly's BOM is the same way, as far as sorting is concerned.  Your best bet right now is doing it manually within the parts list editor dialog.

PartsList.Sort Method 

PartsList.Sort2 Method 

BOMView.Sort Method 

BOMView.Sort2 Method 

 

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 3 of 6

stuart_dean
Explorer
Explorer

Thanks for the reply. I have since found some different bits of code on here which gets me most of the way there by adding a new column called "CATEGORY" and then sorts on that column. The problem is it adds the column to the parts list on the drawing and i cant work out the code i require to remove it after it has been sorted. Any help would be appreciated, current code:-

 

' Set a reference to the drawing document.' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
  
' Set a reference to the first parts list on the active sheet.' This assumes that a parts list is on the active sheet.
Dim oPartList As PartsList
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
 
Dim oPartNumber As PartsListCell
Dim oType As PartsListCell

'Dim oPartNumberLength As Integer'Dim invCharPosition As Integer

' Iterate through the contents of the parts list.
Dim i As Long
For i = 1 To oPartList.PartsListRows.Count
    'Get value from PartNumber column
    oPartNumber = oPartList.PartsListRows.Item(i).Item("PART NUMBER")
    oType = oPartList.PartsListRows.Item(i).Item("CATEGORY")
    
    'Find the 1st 3 characters of the Part Number
    oPartNumberLetter = oPartNumber.Value.ToString().Substring(0,1)
    
    'Return the Part Number as a string
    oPartNumberValue = oPartNumber.Value.ToString()
    
    'Return the number of characters in the Part Number
    oPartNumberLength = Len(oPartNumberValue)

        If oPartNumberLetter = "C" Then
        oType.Value = "1"
        ElseIf oPartNumberLetter = "K" Then
        oType.Value = "2"
        Else If oPartNumberLetter = "S" Then
        oType.Value = "3"
		Else If oPartNumberLetter = "M" Then
        oType.Value = "4"
		Else If oPartNumberLetter = "A" Then
        oType.Value = "5"
		Else If oPartNumberLetter = "S" Then
        oType.Value = "6"
	    Else
        oType.Value = "7"
        End If

Next

oPartList.Sort("CATEGORY", 1, "PART NUMBER", 1)
oPartList.Renumber
oPartList.SaveItemOverridesToBOM

 

0 Likes
Message 4 of 6

Darkforce_the_ilogic_guy
Advisor
Advisor

it might be possible to do .. .but i am not sure i would recommend doing it 

 

the problem is the only way you migh be able to do that override the pos number.  so it macth that your want ... and then sort after the pos number.

 

anyway does your   C, then K, then S, then M, then A, then BOF, then B# have to be in any kind of order just ramdon after that ?

 

C2sdf

C6dfs

C4fgd

 

and so on or does it have to be

 

C2sdf

C4fgd

C6dfs

 

?

 

 

 

 

 

 

 

0 Likes
Message 5 of 6

Darkforce_the_ilogic_guy
Advisor
Advisor
 

 I am not sure it this work  but you might try somthing like this 

oPartList.PartsListRows.Item(i).Item("CATEGORY").Visible= False

 

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes