Forgot password?

Create an account!

Forum

« back

RhinoScript – sort objects by object name?

Messages

Please log in to write a message.

  • 3. dingle (Nov 03, 2009 18.41):

    hi hanno,
    i'll give your second recommendation a shot - i actually used your nsort function before i discovered rhinoscript's sortstring. :) thanks for the help, i'll post what happens.

  • 2. Hanno (Nov 03, 2009 12.06):

    Hi!

    This is one of the things that are not very straightforward in rhinoscript/vbscript, because you would need associative array for it (arrays that can have strings as keys, so you can sort the elements and still keep the connection between key and value).
    You can either look into the vbscript Scripting.Dictionary object, as this is an associative array.
    Or, if you want to stick to arrays, I would suggest making a nested array where every item is an array of (object name, object id). Then you can use the array_nsort method from my array library (look in the scripts section) to sort these arrays by the object name.

    Hope that helps!

    Hanno

  • 1. dingle (Nov 02, 2009 17.48):

    another kinda simple one, but i can't quite wrap my head around it right now. i'm trying to sort objects in an array by their object names. i can get the object names as an array, sort it alphabetically, but how then would i apply the new location of the name in its array to the corresponding original object's position in its array?

    here's a snippet:

            arrSectionLines = Rhino.GetObjects("Select section lines", , True)
            If IsNull(arrSectionLines) Then Exit Sub
           
            'sort section lines by object name
            Dim arrSectionNames, strName, arrSectionNamesSorted
           
            arrSectionNames = Rhino.ObjectNames(arrSectionLines)
           
            arrSectionNamesSorted = Rhino.SortStrings(arrSectionNames, True)
Recommend

Why are these buttons gray?