Sort parts List based on Part Number

Sort parts List based on Part Number

donaldleigh
Advocate Advocate
818 Views
7 Replies
Message 1 of 8

Sort parts List based on Part Number

donaldleigh
Advocate
Advocate

Hi all

 

I have found and modified the below rule to sort our parts list based on the part number.

The part number can be in several formats.

 

Type 1 - Drawing number "18000-01-01" always 11 characters long

Type 2 - DXF number "DXF 18000-01-A" always starts with DXF

Type 3 - Part Number "11111" always 5 characters long

Type 4 - anything else.

 

I keep getting an error with looking at the number of characters or looking for the 1st 3 characters of the part number

Can someone please point me in the right direction.

 

SyntaxEditor Code Snippet

' 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("DWG/PART No.")
    oType = oPartList.PartsListRows.Item(i).Item("PART TYPE")

    oPartNumberLength = Len(oPartNumber)
    oPartNumberStart = Left(oPartNumber,3)

        If oPartNumberLength = 11 Then
        oType.Value = "DWG"
        
        Else If oPartNumberStart = "DXF" Then
        oType.Value = "DXF"
        
        Else If oPartNumberLength = 5 Then
        oType.Value = "STD"
        
        Else
        oType.Value = "Other"
        
        End If
Next

oPartList.Sort("PART TYPE")
oPartList.Renumber
oPartList.SaveItemOverridesToBOM

Cheers

Donald

Inventor 2014

 

0 Likes
Accepted solutions (2)
819 Views
7 Replies
Replies (7)
Message 2 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@donaldleigh,

 

Try below iLogic code to get first 3 letters from a string.

 

oPartNumberStart = oPartNumber.Substring(0,3)

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 8

donaldleigh
Advocate
Advocate

Hi @chandra.shekar.g

 

I get the following error

 

Public member 'Substring' on type 'PartsListCell' not found.

 

Donald

0 Likes
Message 4 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@donaldleigh,

 

Some times oPartNumber would be a numeric or double. Try below code.

 

oPartNumberStart = oPartNumber.ToString().Substring(0,3)

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 8

donaldleigh
Advocate
Advocate

Hi @chandra.shekar.g

 

This returns the text "System._ComObect" with the number is changed from 3 to 19

Donald

 

0 Likes
Message 6 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@donaldleigh,

 

I thought oPartNumber was string. But it is a type of PartsList. Try below code.

 

oPartNumberStart = oPartNumber.Value.ToString().Substring(0,3)

Thanks and regards,

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 8

donaldleigh
Advocate
Advocate

Hi @chandra.shekar.g

 

That worked for finding the 1st 3 characters off the part number. thanks

 

But now I also need to find how many characters are in the part number to work out if its a Drawing Number or Part Number.

 

Donald

0 Likes
Message 8 of 8

donaldleigh
Advocate
Advocate
Accepted solution

Hi @chandra.shekar.g

 

I got it sorted

 

Here is my final code. Thanks for your help with this.

 

SyntaxEditor Code Snippet

' 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("DWG/PART No.")
    oType = oPartList.PartsListRows.Item(i).Item("PART TYPE")
    
    'Find the 1st 3 characters of the Part Number
    oPartNumberDXF = oPartNumber.Value.ToString().Substring(0,3)
    
    'Return the Part Number as a string
    oPartNumberValue = oPartNumber.Value.ToString()
    
    'Return the number of characters in the Part Number
    oPartNumberLength = Len(oPartNumberValue)

        If oPartNumberDXF = "DXF" Then
        oType.Value = "DXF"
        ElseIf oPartNumberLength = 11 Then
        oType.Value = "DWG"
        Else If oPartNumberLength = 5 Then
        oType.Value = "STD"
        Else
        oType.Value = "Other"
        End If

Next

oPartList.Sort("PART TYPE", 1, "DWG/PART No.", 1)
oPartList.Renumber
oPartList.SaveItemOverridesToBOM

 

0 Likes