sort arrylist

sort arrylist

Anonymous
Not applicable
1,249 Views
6 Replies
Message 1 of 7

sort arrylist

Anonymous
Not applicable

Hello

I have an array that consists of the largest overall size and location. Now I would like to sort of smallest overall size to the largest. I can not split the array because I want to open in the next stage the parts from small to big and I need the location for this action.

So how can I sort the array so that I can open the parts from small to large.

 

Sub Main()





' Get the active assembly document.
 Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
 ' Iterate through all of the documents referenced by the assembly.
 Dim oDoc As Document

Dim laserwerklist As New ArrayList 




For Each oDoc In oAsmDoc.AllReferencedDocuments

'Try

' Verify that the document is a part.
 If oDoc.DocumentType = kPartDocumentObject Then
 Dim oPartDoc As PartDocument = oDoc
 'Manipulate part 

 Dim model As String = oPartDoc.FullFileName
 Dim emodel As String = oPartDoc.DisplayName
 'emodel = emodel & ".ipt"

eMuppet = Left(iProperties.Value(emodel,"summary","category"),5)

'MessageBox.Show(eMuppet, "Title")

If eMuppet = "Laser" Then

overmeten=iProperties.Value(emodel,"Custom", "lengte")'dit is de overmeten lengte


laserwerklist.add(overmeten &" "& model )



'laserwerk.sort()




Else

End If

End If

'Catch
 'End Try

Next



myComponent = InputListBox("Select one.", laserwerklist, laserwerklist.item(4), "iLogic", "List")


end sub

 Thanks in advance

 

0 Likes
1,250 Views
6 Replies
Replies (6)
Message 2 of 7

MechMachineMan
Advisor
Advisor
laserwerklist.Reverse()

 

Google-fu is a wonderful thing.


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

Anonymous
Not applicable

Thank you for the reply but is not what I mean. I know this command. Maybe my explanation is not completely clear so I still have a picture of what I want as a solution

help.png

 

 

 

 

0 Likes
Message 4 of 7

MechMachineMan
Advisor
Advisor

What does it do when you UNcomment your sort line?

 

laserwerk.sort()

--------------------------------------
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 7

Anonymous
Not applicable

 na sort.JPG

 

It sorts as a string

 

 

0 Likes
Message 6 of 7

rikard.nilsson
Collaborator
Collaborator
Hi,

If I would have done this I would do it with one of these 2 solutions.

Create a List with my own created Class with (Length as Double, fileName as String) and after that sort on Length.

Or use a Dictionary(of String, Double) and after that sort on Value. Wich is the Length.

Most of the times I use my first suggestion with my Class.

Regards
Rikard
0 Likes
Message 7 of 7

Anonymous
Not applicable

yesterday evening I have found a solution. I made a test with a simple example. What do you think of this solution. Is this ok?

 This evening I will do a test with your solution. Can you give me a example of you solution? 

Thanks in advance

 

 

Dim Dictionary As New Dictionary(Of String, Integer)
        Dictionary.Add("please", 32)
        Dictionary.Add("help", 16)
        Dictionary.Add("program", 256)
        Dictionary.Add("computers", 1)

           'Dim test As Integer  
           Dim test As New ArrayList
Dim muppet As New ArrayList

        ' Loop over entries.
        Dim pair As KeyValuePair(Of String, Integer)
		
		
				For Each pair In Dictionary
            ' Display Key and Value.
          
			
			
			
			
			test.add(pair.Value)
			
			
			
			
			
			'MsgBox(pair.Value)
        Next
		
		
		
		
		
		test.sort
		
		
		'myComponent = InputListBox("Select one.", test, test.item(1), "iLogic", "List")
		
		Dim kom As String
		For Each item In test
		For Each pair In Dictionary
		
		'For Each item In test
		
		
		If item = pair.Value
		
		kom= item & "-" & (pair.key)
		
		muppet.add(kom)
		
		Else 
		
	      
		
		End If
		
		
		Next
		
		Next
		
		
		
myComponent = InputListBox("Select one.", muppet, muppet.item(1), "iLogic", "List")

  

0 Likes