Forgot password?

Create an account!


« back

RhinoScript – Need Help with sorting an array based on Coordinates in Rhino


Please log in to write a message.

  • 2. CyberiumShadow (Mar 31, 2016 03.20):

    Consider this thread closed.

    I've worked it out myself

  • 1. CyberiumShadow (Mar 30, 2016 06.39):

    Hi there,

    I'm currently trying to script something that will automatically amend a client's labelling of thier metal work order for our factories to use.

    Right now I've noticed that running my script without a sort function just amends the labels based on the object id number, not based on left to right top down.

    Here is a copy of the code so far, and yes, I have used major aspects of the mcneel example script.

    Option Explicit
    'Script written by <Johnson Chen>
    'Script copyrighted by <Metrix Group>
    'Script version Wednesday, 30 March 2016 11:04:14 AM

    'This script is designed to allow panel numbers in Rhino to be appended with a sequential numerical prefix
    'A majority of this code is based on McNeel's Auto Label Script.
    Sub AutoLabel_Append
            'Declare Variables
            Dim arrSortDir, arrObjects, arrPoint, arrItem, arrCollect()
            Dim strObject, strName, strText, strAppend
            Dim intCount, intSuffix
            Dim i, j, temp
            'Text Objects are automatically selected -REMOVED-
            'Text Objects are manually selected by user, Only Text Objects can be selected.
            arrObjects = Rhino.GetObjects("Select text to edit", 512, True, True)
            ' Prompt for a prefix to add to the labels
            strText = Rhino.GetString("Prefix for labels, press Enter for none")
            If Not IsString(strText) Then Exit Sub

            ' Prompt for a suffix starting number
            intSuffix = Rhino.GetInteger("Starting base number to increment", 0)
            ' Initialize collection counter
            intCount = 0
            'Process each Text Object into the Array *WIP*
            For Each strObject In arrObjects
                    'Determines the Location of the Text Object
                    arrPoint = Rhino.TextObjectPoint(strObject)
                    ' Append the object name to the point array
                    ReDim Preserve arrPoint(3)
                    arrPoint(3) = strObject
                    ' Append the modified point array to the collection    
                    ReDim Preserve arrCollect(intCount)
                    arrCollect(intCount) = arrPoint
                    ' Increment collection counter
                    intCount = intCount + 1
            ' Validate the collection
            If Not IsUpperBound(arrCollect) Then Exit Sub

            'Generate Prefixes to Append
            ' Process each item in the collection
            For i = 0 To UBound(arrCollect)
                    ' Get an item from the collection
                    arrItem = arrCollect(i)
                    ' Rebuild the point array
                    arrPoint = Array(arrItem(0), arrItem(1), arrItem(2))
                    'Need to change Rhino.AddText to something that can APPEND a string within an array. Maybe use VBScript to implement?
                    strAppend = Rhino.TextObjectText(arrItem(3))
                    strAppend = strText & Cstr(intSuffix + i) & " " & strAppend
                    Rhino.TextObjectText arrItem(3), strAppend

    End Sub

    ' Returns a Boolean value indicating whether an
    ' expression can be evaluated as a string
    Function IsString(ByVal str)
            IsString = False
            If VarType(str) = vbString Then IsString = True
    End Function  

    ' Returns a Boolean value indicating whether an
    ' array has been dimensioned.
    Function IsUpperBound(ByVal arr)
            IsUpperBound = False
            If IsArray(arr) Then
                    On Error Resume Next
                    UBound arr
                    If Err.Number = 0 Then IsUpperBound = True
            End If
    End Function

    Any help would be appreciated. Cheers


Why are these buttons gray?