Creating a sorting application/feature in vb.net

Creating a sorting application/feature in vb.net

MechMachineMan
Advisor Advisor
2,244 Views
14 Replies
Message 1 of 15

Creating a sorting application/feature in vb.net

MechMachineMan
Advisor
Advisor

My goal is to be able to take a bunch of data from the BOM, sort it conditionally, and then return a simple list with the document names.

 

I've come across some good information on LINQ and iComparable for structures/strings but could use some further guidance in what I need to do to make this happen.

 

Essentially it will be a multi level sort with some logic like:

 

-> Put objects with 'Drawing' = True first.

-> Sort then by ComponentDefinition/Secondary document desciber;

        (ie; assemblies and weldments, then plate, then structural steel, then hardware).

     

        -> Sort Assemblies and weldments by Renamed vs Matl'l Spec then by weight

        -> Sort Structural by type, then by size

        -> Sort hardware by nomial size, then by type, then by thread unc/unf, then by length

        -> Put the remainder last (ie; virtual components.

 

From what I've read, it seems like I can accomplish this by multiple sets of linq's if I can get it working,

 

Or I can use a Compare function and just compare each line in its entirety to the next (as my understand of it would suggest?)

 

So at the end of the day, I would want a list to spit out something like:

 

3) Drawing - Weldment - Named - Weight

1) Drawing - Assembly - Named - Weight

2) Drawing - Assembly - Unnamed - Weight

3) Drawing - Weldment - unnamed - weight

3) Drawing - Plate - 1" Thick x 48 sq in.

4) Drawing - Plate - 1" Thick x 36 sq in.

5) No Drawing - Plate - 1" Thick X 52 in

6) No Drawing - Plate - 1/2" thick X 52 in

7) No Drawing - 1/2" Bolt - UNC - 3"

8) No Drawing - 1/2" Bolt - UNC - 2"

9) No Drawing - 1/2" Nut - UNC

10) No Drawing - 1/2" Washer

11) No Drawing - 1/4" Bolt - UNC - 2"

12) No Drawing - Virtual Component 

 

Any suggestions/help on the best way to do this would be great, thanks!


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Accepted solutions (1)
2,245 Views
14 Replies
Replies (14)
Message 2 of 15

Jef_E
Collaborator
Collaborator

Do you mean using natural sort to sort the list?

http://blog.codinghorror.com/sorting-for-humans-natural-sort-order/



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 3 of 15

MechMachineMan
Advisor
Advisor
I think maybe what the one commenter was saying about trees was more along
the lines. I essentially need a multi-tiered sort/ a
primary,secondary,tertiary, etc.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 15

MechMachineMan
Advisor
Advisor

Something sort of like this is what I want to get working; however this is riddles with many errors.

But using the Case 0 as the next level, and making a tree sort seems like the right way to do it, as long as I can get the basic tree working.

That way, I'm only sorting items based on how they ended up in the previous sort. (No need to go any further if I'm comparing an assembly to hardware as would be the secondary level of my sort after the Drawing/NoDrawing sort)

'Jagged Array Sorting with Tag Array
Sub Main()

Dim oBOMRowCount As Integer = 4

Dim oBOMFactorArray As Double(oBOMRowCount-1)(){}
    oBOMFactorArray(0) = {"2", "5"}
	oBOMFactorArray(1) = {"1", "5"}
	oBOMFactorArray(2) = {"1", "2"}
	oBOMFactorArray(3) = {"2", "7"}
	
Dim tagArray() As Integer = {0, 1, 2, 3}

' Initialize the comparer and sort
Dim myComparer As New RectangularComparer(oBOMFactorArray)
Array.Sort(tagArray, myComparer)

Dim i As Integer
For j = 0 To 3
	oLine = ""
	For i = 0 To 1
		If oLine = ""
			oLine = "oList[" & (oBOMFactorArray(j)(i)) & "]"
		Else
			oLine = oLine & "[" & (oBOMFactorArray(j)(i)) & "]"
		End If
	Next
	oStr = oStr & vbLf & oLine
Next
MsgBox(oStr)

End Sub()

Class RectangularComparer
  Implements IComparer
  ' maintain a reference to the 2-dimensional array being sorted

  Private sortArray(,) As Integer

  ' constructor initializes the sortArray reference
  Public Sub New(ByVal theArray(,) As Double)
    sortArray = theArray
  End Sub

  Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
    ' x and y are integer row numbers into the sortArray
    Dim i1 As Integer = DirectCast(x, Integer)
    Dim i2 As Integer = DirectCast(y, Integer)

	Select Case sortArray(i1, 0).CompareTo(sortArray(i2, 0))
		Case -1
		Case 1
		Case 0
				Return sortArray(i1, 1).CompareTo(sortArray(i2, 1))
	End Select
    ' compare the items in the sortArray
  End Function
End Class

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 15

Anonymous
Not applicable
Accepted solution

I created a multi teir sorter within a custom sort routine for sorting my drawings with a particular order (not alphabetic).  In the sort comparer function I created a custom class (small 3 properties) that broke down my information from a single text string, into 3 groups of data, Drawing, Project, Series, then I created 3 more properties that 'ranked' each value numerically.  Drawing was the fun one, because it required a select case statement to turn each random alphabetic letter into a number that put the drawing in order.  Then I sorted the final product with qualifying if/then statements, it looks something like this:

 

Public Class DrawingSortComparer
    Implements IComparer(Of String)

    Public Function Compare1(ByVal x As String, ByVal y As String) As Integer Implements IComparer(Of String).Compare
        If x Is Nothing And y Is Nothing Then Return 0
        If x IsNot Nothing And y Is Nothing Then Return 1
        If x Is Nothing And y IsNot Nothing Then Return -1
        If x IsNot Nothing And y IsNot Nothing Then
            'get filenames without extensions or folders
            x = System.IO.Path.GetFileNameWithoutExtension(x)
            y = System.IO.Path.GetFileNameWithoutExtension(y)
            'first remove any PDF reference to a Revsison
            x = x.ToString.Split(" - ")(0)
            y = y.ToString.Split(" - ")(0)
            'split the string and see if it is a valid drawing number
            Dim dnX As New DrawingNumber(x.ToString)
            Dim dnY As New DrawingNumber(y.ToString)
            If dnX.isDrawingNumber And dnY.isDrawingNumber Then
                'first sort on drawing type:
                If (dnX.DTValue < dnY.DTValue) Then
                    Return -1
                ElseIf (dnX.DTValue > dnY.DTValue) Then
                    Return 1
                Else 'Values are equal - keep digging or - Return 0
                    If (dnX.PRValue < dnY.PRValue) Then
                        Return -1
                    ElseIf (dnX.PRValue > dnY.PRValue) Then
                        Return 1
                    Else 'Values are equal - keep digging or - Return 0
                        If (dnX.Serial < dnY.Serial) Then
                            Return -1
                        ElseIf (dnX.Serial > dnY.Serial) Then
                            Return 1
                        End If
                    End If
                End If
            End If
        End If
        Return New System.Collections.CaseInsensitiveComparer().Compare(x, y)
    End Function

    'Public Function Compare(x As String, y As String) As Integer Implements IComparer.Compare

    'End Function

    Private Class DrawingNumber
        Property DrawingType As String
        Property Project As String
        Private strSplit() As String
        Property isDrawingNumber As Boolean = True

        ReadOnly Property DTValue As Long
            Get
                If strSplit.Count = 3 Then
                    DrawingType = strSplit(0)
                    Select Case DrawingType
                        Case Is = "N"
                            Return 0
                        Case Is = "S"
                            Return 1
                        Case Is = "C"
                            Return 2
                        Case Is = "T"
                            Return 3
                        Case Is = "G"
                            Return 4
                        Case Is = "M"
                            Return 5
                        Case Is = "A"
                            Return 6
                        Case Is = "D"
                            Return 7
                        Case Is = "P"
                            Return 8
                        Case Is = "L"
                            Return 9
                        Case Else
                            isDrawingNumber = False
                    End Select
                Else
                    isDrawingNumber = False
                End If
                Return 10
            End Get
        End Property

        ReadOnly Property PRValue As Long
            Get
                If strSplit.Count = 3 Then
                    Project = strSplit(1)
                    If Project.Length = 5 Then
                        If IsNumeric(Project) Then
                            PRValue = Project 'this should put numeric 5 digit projects in front of aphabetic 5 digit projects
                        Else
                            PRValue = String.Join(String.Empty, From c In Project.ToCharArray Select (Asc(c).ToString))
                        End If
                        Return PRValue
                    Else
                        isDrawingNumber = False
                    End If
                Else
                    isDrawingNumber = False
                End If
                Return 99999 '10 digits
            End Get
        End Property

        ReadOnly Property Serial As Double
            Get
                If strSplit.Count = 3 Then
                    'Try
                    If IsNumeric(strSplit(2)) Then
                        Return CType(strSplit(2), Double)
                    Else
                        isDrawingNumber = False
                        Return 9999999
                    End If
                    'Catch ex As Exception
                    'isDrawingNumber = False
                    'End Try
                End If
                isDrawingNumber = False
                Return 9999999 'expected up to 7 whole digits (decimal reserved for tabulated parts)
            End Get
        End Property

        Public Sub New(strDrawing As String)
            strDrawing = Path.GetFileNameWithoutExtension(strDrawing)
            strSplit = strDrawing.Split("-")
            strDrawing = DTValue & PRValue & Serial
        End Sub

    End Class

It is used like this:

 

    Public Sub SortFiles(ByRef inputList As List(Of String))
        Dim dsc As New DrawingSortComparer
        inputList.Sort(dsc)
    End Sub

Took a while to master, but works great.  Good luck with yours.

 

Message 6 of 15

MechMachineMan
Advisor
Advisor

My Good Lord. That looks awesome and like exactly what I was looking for!

 

Thanks so much! Saves me brute forcing a hard coded/ugly If/Select Case Tree!.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 15

MechMachineMan
Advisor
Advisor
So I see this works on a list of file names which is awesome and workable.
I haven't used properties before, but I'm assuming the Property section is only run when they are called; like in this string, which calls all 3 that then runs each properties code to return the value?

strDrawing = DTValue & PRValue & Serial

Further, properties can also be queried globally from outside of their class, by calling the class as in:

If dnX.isDrawingNumber And dnY.isDrawingNumber Then

Which essentially just cleans up the code by not making you have to put the extractions of that info in the main loop?

Then finally there is the Properties called within the class such as

Property DrawingType As String

which are just to be used locally as a variable, within the class (much like a Dim)


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 8 of 15

Anonymous
Not applicable

For the most part a property functions like a single dim, UNTIL, you add custom code in the Get/Set statements.  Whenever defining a class, I tend to use Property before Dim, because I never know when I want that object value exported, or customized.  Also anything defined as Property, will be usable from code behind on a WPF XAML page as a bindable value (after compiling).

0 Likes
Message 9 of 15

MechMachineMan
Advisor
Advisor

So going forward, my best bet is to use properties to create my sort index; so it will be something like:

 

Property SearchFactor1
If Not oDwgNumberProp =""
      Return 0
Else 'If no drawing, return 1
       Return 1
End if

 

Property SearchFactor2
Open Part Doc
If OpenPartDocDescrip  Like PL.
    Return 1
Else if .... Like HSS
   Return 2
ELse if PartDocType = Assembly
  Return 3
End if

 

Property SearchFactor3
If SearchFactor2 < 3 ' If part, 3rd factor is length
       FunctionStripPartLength
       Return PartLength
Else   ' if assembly, 3rd factor is weight
       FetchWeight
      Return Weight
End if

 

Then in my compare, if I want factor 3 to be sorted ascending for plate length, and descending for weight, I just need to perform another check against the SearchFactor 2, correct?

This way I can use a simple Integer Comparison to decide the results of the sort, right?


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 10 of 15

Anonymous
Not applicable

Not going to pretend I know your sorting needs, but yes I found integer/double comparison to turn out way more reliable than alphabetic.  One attempt I ran was to add all the integers up and sort on only 1 massive number, but that failed miserably when the number got too big to compare.  So I settled on breaking down each descision of property one at a time, hence the complex if/then statements.  If you talk yourself through the sorting decision, your code should easily follow.

0 Likes
Message 11 of 15

MechMachineMan
Advisor
Advisor

So I have been playing with this for a bit, and I ran into a weird issue: The Comparison isn't even looking at some values. (at least checking by what gets pulled into the Compare right away.

 

It isn't comparing entries 2 and 4 in the sort, which makes it impossible for me to sort it correctly. 

 

Currently just working with this to understand the function of it all a bit better, which seems like a good idea judging by this error!

 

See below for the code (I'm just doing my programming inside of the inventor environment, which is probably pretty amateur of me.) 

 

Public Sub Main
   Dim CustCompare As New BOMSortComparer
	
	Dim inputList As New List(Of String)
	
	inputList.Add("Drawing,Assembly,2400")
	inputList.Add("No Drawing,PL.,1/4,OD")
	inputList.Add("No Drawing,PL.,1/4,23")
	inputList.Add("No Drawing,PL.,1/4,22")
	inputList.Add("Drawing,PL.1/2,")
	inputList.Add("No Drawing,HW, 1-1/4,BOLT")
	
	For j = 0 To inputList.Count-1
		If j = 0
			oPreStr = inputList.Item(j)
		Else
			oPreStr = oPreStr & vbLf & inputList.Item(j)
		End If
	Next 

inputList.Sort(CustCompare)

	For k = 0 To inputList.Count-1
		If k = 0
			oPostStr = inputList.Item(k)
		Else
			oPostStr = oPostStr & vbLf & inputList.Item(k)
		End If
	Next 	
	MsgBox("Pre:" & vbLf & oPreStr & vbLf & vbLf & "Post:" & vbLf & oPostStr)

 End Sub

Public Class BOMSortComparer
    Implements IComparer(Of String)
    Public Function Compare(ByVal x As String, ByVal y As String) As Integer Implements IComparer(Of String).Compare
        MsgBox(x & vbLf & y)
		If x Is Nothing And y Is Nothing Then Return 0
        If x IsNot Nothing And y Is Nothing Then Return 1
        If x Is Nothing And y IsNot Nothing Then Return -1
        If x IsNot Nothing And y IsNot Nothing Then 

            'run the property feature.
            Dim sfX As New SearchField(x.ToString)
            Dim sfY As New SearchField(y.ToString)
			If sfx.SearchFactor1 > sfy.SearchFactor1
				'MsgBox("sfX.SearchFactor1:" & sfx.SearchFactor1 & " - " & x.ToString & vbLf &"sfY.SearchFactor1:" & sfy.SearchFactor1 & " - " & y.ToString & vbLf & vbLf & "1")
				Return 1
			ElseIf sfx.SearchFactor1 < sfy.SearchFactor1
				'MsgBox("sfX.SearchFactor1:" & sfx.SearchFactor1 & " - " & x.ToString & vbLf &"sfY.SearchFactor1:" & sfy.SearchFactor1 & " - " & y.ToString & vbLf & vbLf & "-1")
				Return -1
			Else
				'MsgBox("sfX.SearchFactor1:" & sfx.SearchFactor1 & " - " & x.ToString & vbLf &"sfY.SearchFactor1:" & sfy.SearchFactor1 & " - " & y.ToString & vbLf & vbLf & "0")
				Return 0
			End If

		End If
        Return New System.Collections.CaseInsensitiveComparer().Compare(x, y)
    End Function
End Class

Public Class SearchField

	'Property Is like dim, but can be easily used globally and have Get features; could also use dim but that would just be local	
Property Field1 As String
Property Field2 As String
Property Field3 As String

ReadOnly Property SearchFactor1 As Integer
    Get
       Select Case True
	   		Case Field1 = "No Drawing"
				Return 0
			Case Else
				Return 1
			End Select
    End Get
End Property


        Public Sub New(ListItem As String)
			'MsgBox(ListItem)
			
     		Dim words() As String = ListItem.Split({","}, StringSplitOptions.RemoveEmptyEntries)

			Field1 = words(0)
			Field2 = words(1)
			Field3 = words(2)
'			MsgBox("Field1: " & words(0) & vbLf & _
'				   "Field2: " & words(1) & vbLf & _
'				   "Field3: " & words(2))
        End Sub

 End Class

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 12 of 15

Anonymous
Not applicable

i bet its in your split of the ",".  list item 1 has 3 split objects list item 2 has 4 split objects.  Its that 4th object that is not getting accounted for because you are only storing 3 values for comparison.

 

The VBAIDE editor inside of Inventor is not an issue with the exception that a visual studio editor, has better debugging tools.  It would help you to stop the code, inspect what is in memory, and even change it on the fly if you like.  If you haven't gotten it already, I suggest getting visual studio express, or better.  I have VS 2015 Pro, and like it well, but its not free!  As such I have also chosen to write all my code in an external exe that grabs or creates an inventor application.  Sure I could create a app addin/plug in/ and such that works directly inside of Inventor, but my tools do not need to shut down Inventor to reload, making debugging even more fun.  I don't think there is really a right or wrong way for anything here, or novice vs master either.  You get experience as you plug along learning to 'master' the API.  Cool thing about Inventor API, unlike AutoCAD, is that each method (VB.Net, VBA, iLogic) all use very similar if not identical object model and nearly identical syntax.  So if I prove something out in iLogic or VB, i can place it in the other pretty easily.

0 Likes
Message 13 of 15

MechMachineMan
Advisor
Advisor
Hmmm. I'll have to try it out. As it is, if I put in a msgbox to show x and
y at the very top of the compare function, it only ever shows a couple of
the names.

It's almost like the compare is just comparing the elements based on the
index, so as soon as it moves 1, it excludes another; ie it's actually
sorting elements 1 through 6, but doesn't look like it because it swaps the
values before it looks at the elements again?

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 14 of 15

MechMachineMan
Advisor
Advisor

After more trial-and-error,

 

the compare sorts fine by string.... except as soon as I make a call to the SearchField Class; ie 

 

Dim sfX As New SearchField(x.ToString)

 the compare then will not compare a predictable amount of values. Sometimes it only does 1 comparison, other times it does 4.... Every time I exclude the SearchField, it compares all List items and all combinations as is expected.

 

With Searchfield call:

Comparison 1: ListItem1 vs List Item 3

No More comparisons done..

 

Without.

Comparison 1: ListItem1 vs List Item 3

Comparison 2: ListItem3 vs List Item 6

Comparison 4: ListItem4 vs List Item 5

etc, until all combinations are compared.

 

This was check by using:

 

SyntaxEditor Code Snippet

Public Class BOMSortComparer
    Implements IComparer(Of String)
    Public Function Compare(ByVal x As String, ByVal y As String) As Integer Implements IComparer(Of String).Compare
        MsgBox(x & vbLf & y)
End Function


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 15 of 15

MechMachineMan
Advisor
Advisor
Thanks again for the responses... You were most definitely right; it was the issue with the split throwing an error, but nothing showing on my end;

Inventor will usually crash and show the error stack right away, but it's like in the method it is hidden within it's own loop.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes