Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
GeorgK
634 Views, 7 Replies

sorting bom problem

Hello together,

 

I have a problem to sort my drawing bom. The first step is to sort the "part number" ascending, which is working.

 

Public Sub PartListEdit()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set 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
    Set oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
    
    ' Iterate through the contents of the parts list.
    Dim i As Long
    For i = 1 To oPartList.PartsListRows.Count
        ' Get the current row.
        Dim oRow As PartsListRow
        Set oRow = oPartList.PartsListRows.Item(i)
        
        ' Iterate through each column in the row.
        Dim j As Long
        For j = 1 To oPartList.PartsListColumns.Count
            ' Get the current cell.
            Dim oCell As PartsListCell
            Set oCell = oRow.Item(j)
            
            
            If oPartList.PartsListColumns.Item(j).Title  "Part number" Then
                'Do some work
            End If
        Next
    Next
    
   
End Sub

In the next step I would like to sort the parts with the name from 1 to x

  1. S000AxxxxxxxxxP001
  2. S000AxxxxxxxxxP002
  3. S000AxxxxxxxxxP003

 

xxxxxxxxx could be numbers or text.

 

The remaining parts should get a number from 100 to xx
How could I do this?

 

Thank you

Georg

 

GeorgK
in reply to: GeorgK

The bom columns:

 

No.; Qty.; Part number; Title

chandra.shekar.g
in reply to: GeorgK

 @GeorgK ,

 

Hoping that below iLogic code may be helpful to sort substring of string.

Dim list1() As String = {"abc0002", "aab0001", "abb0005", "aaa0003", "aed0004"}
Dim result = list1.OrderBy(Function(q) q.Substring(5)).ToArray

For Each s As String In result
    MessageBox.Show(s)
Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



GeorgK
in reply to: chandra.shekar.g

Hello @chandra.shekar.g ,

 

thank you for the sample. It's not the problem to sort the list. The problem is to sort the partlist. Please could you send me an example.

 

Thank you

Georg

chandra.shekar.g
in reply to: GeorgK

@GeorgK ,

 

Please send me sample partslist with expected result and make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



GeorgK
in reply to: chandra.shekar.g

Sorted partlist:

Partlist.png

 

But there could also some parts with a or b at the beginning which should be positioned after the S00xxxxxxPxx parts.

 

 

chandra.shekar.g
in reply to: GeorgK

@GeorgK ,

 

Hoping that below iLogic code may be helpful to sort part numbers.

 

Dim oDoc As DrawingDocument 
oDoc = ThisApplication.ActiveDocument 

Dim oSheet As Sheet 
oSheet = oDoc.ActiveSheet 

Dim oPartslist As PartsList
oPartslist = oSheet.PartsLists.Item(1)

Dim oRow As PartsListRow 
 
Dim myList As New List(Of String)()
Dim i As Integer  
For Each oRow In oPartslist.PartsListRows 
	If oRow.Item(3).Value.Length = 13 Then
		myList.Add(oRow.Item(3).Value)
	End If 
Next
Dim list() As String = myList.ToArray()
Dim result = list.OrderBy(Function(q) q.Substring(11)).ToArray

i = 1
For Each s As String In result
    For Each oRow In oPartslist.PartsListRows 
		If s = oRow.Item(3).Value Then
			Call oRow.Reposition(i)
			i = i + 1
		End If
	Next 
Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



GeorgK
in reply to: chandra.shekar.g

Hello @chandra.shekar.g ,

 

thank you very much. I didn't thought about Reposition the row.

 

Georg