Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:selnamedobject [2015/09/14] (current)
Line 1: Line 1:
 +====== Select Named Objects from a List ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrates how to use a dialog box to select named objects using [[developer:​rhinoscript|RhinoScript]].//​
 +
 +=====Example=====
 +Rhino'​s **SelName** selects visible objects with a specified name. But, this command only has a command line interface. The following sample script demonstrates how to use a dialog box to select visible objects with a specified name using [[developer:​rhinoscript|RhinoScript]].
 +
 +
 +<code vb>
 + ​Option Explicit
 +
 + Sub SelNamedObjects
 +
 +   '​ Get all the objects in the document
 +   Dim arrAll
 +   ​arrAll = Rhino.AllObjects
 +   If Not IsArray(arrAll) Then
 +     ​Rhino.Print "No objects added to selection."​
 +     Exit Sub
 +   End If
 +
 +   '​ Find all of the object names    ​
 +   Dim arrNames(), strName, nBound, i
 +   ​nBound = 0
 +   For i = 0 To UBound(arrAll)
 +     ​strName = Rhino.ObjectName(arrAll(i))
 +     If Not IsNull(strName) Then
 +       ReDim Preserve arrNames(nBound)
 +       ​arrNames(nBound) = strName
 +       ​nBound = nBound + 1
 +     End If
 +   Next
 +
 +   '​ Exit if no names found
 +   If nBound = 0 Then
 +     ​Rhino.Print "No objects added to selection."​
 +     Exit Sub
 +   End If
 +
 +   '​ Cull the duplicate names    ​
 +   Dim arrCulled
 +   ​arrCulled = Rhino.CullDuplicateStrings(arrNames)  ​
 +
 +   '​ Sort the list alphabetically  ​
 +   Dim arrSorted
 +   ​arrSorted = Rhino.Sort(arrCulled) 'Error =>​SortStrings
 +
 +   '​ Select one or more objects names from a list    ​
 +   Dim arrSelected
 +   ​arrSelected = Rhino.MultiListBox(arrSorted,​ "​Object names to select",​ "​Select Named Objects"​)
 +   If Not IsArray(arrSelected) Then Exit Sub
 +
 +   '​ Select, and count, the objects
 +   Dim arrObjs, nCount
 +   ​nCount = 0
 +   For i = 0 To UBound(arrSelected) ​   ​
 +     ​arrObjs = Rhino.ObjectsByName(arrSelected(i),​ True)
 +     If IsArray(arrObjs) Then
 +       ​nCount = nCount + UBound(arrObjs) + 1
 +     End If
 +   Next
 +
 +   '​Print report to commandline
 +   If nCount = 0 Then
 +     ​Rhino.Print "No objects added to selection."​
 +   ​ElseIf nCount = 1 Then
 +     ​Rhino.Print "1 object added to selection."​
 +   Else
 +     ​Rhino.Print CStr(nCount) & " objects added to selection."​
 +   End If
 +
 + End Sub
 +
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/selnamedobject.txt ยท Last modified: 2015/09/14 (external edit)