McNeel Wiki
More on Sorting Key-Value Pairs
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

中文(简体)

 
.
DeveloperRhinoScript
Version4.0
SummaryDemonstrates how to sort an array of key-value pairs in RhinoScript.

Also See

Key-Value pair QuickSort algorithm

Question

How does one sort an array of key-value pairs using RhinoScript?

Answer

The .NET Framework's SortedList class provides a hash table with automatically sorted key-value pairs. The available methods and properties for SortedList are very similar to the ones available in ArrayList.

The following sample code creates a SortedList and populates it with some key-value pairs:

  Set SortedList = CreateObject("System.Collections.Sortedlist")


  SortedList.Add "First", "Hello"
  SortedList.Add "Second", ","
  SortedList.Add "Third", "Rhino"
  SortedList.Add "Fourth", "!"


  For i = 0 To SortedList.Count - 1
    Rhino.Print SortedList.GetKey(i) & vbTab & SortedList.GetByIndex(i)
  Next

Note, SortedList only sorts the list by keys. It is not possible to sort the list by values.

rename · changes · history · subscriptions · lost and found · references · file upload