- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- S000AxxxxxxxxxP001
- S000AxxxxxxxxxP002
- 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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sorted partlist:
But there could also some parts with a or b at the beginning which should be positioned after the S00xxxxxxPxx parts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report