Site Tools


Differences

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

Link to this comparison view

developer:scriptsamples:isolatelayers [2015/09/14] (current)
Line 1: Line 1:
 +====== How To: Isolate the Layers of Selected Objects ======
 +====== RhinoScript ======
 +> **Summary:​** //​Demonstrates how to isolate the layers of selected objects using [[developer:​rhinoscript|RhinoScript]].//​
 +
 +<code vb>
 + ​Option Explicit
 +
 + Sub IsolateLayers()
 +
 +   '​ Select objects
 +   Dim objects
 +   ​objects = Rhino.GetObjects("​Select objects on layers to isolate",​ , True, True)
 +   If Not IsArray(objects) Then Exit Sub
 +
 +   '​ Determine the number of selected objects
 +   Dim bound
 +   bound = UBound(objects)
 +
 +   '​ Create an array to the object layer names
 +   Dim object_layers()
 +   ReDim object_layers( bound + 1 )
 +
 +   '​ Fill the array
 +   Dim i
 +   For i = 0 To bound
 +     ​object_layers(i) = Rhino.ObjectLayer(objects(i))
 +   Next
 +
 +   '​ Don't forget to include current layer      ​
 +   ​object_layers(bound + 1) = Rhino.CurrentLayer
 +
 +   '​ Cull any duplicate layer names
 +   Dim culled_layers
 +   ​culled_layers = Rhino.CullDuplicateStrings(object_layers)
 +
 +   '​ Create an array containing all of the layer names
 +   Dim all_layers
 +   ​all_layers = Rhino.LayerNames
 +
 +   '​ For each layer name, search the list of culled layer names.
 +   '​ If the layer name is not found, then turn it off.
 +   Dim layer
 +   For Each layer In all_layers
 +     If UBound(Filter(culled_layers,​ layer)) < 0 Then
 +       ​Rhino.LayerMode layer, 1
 +     End If
 +   Next
 +
 + End Sub
 +
 +</​code>​
 +
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/isolatelayers.txt ยท Last modified: 2015/09/14 (external edit)