Site Tools


Differences

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

Link to this comparison view

developer:scriptsamples:exportlayerobjects [2015/09/14] (current)
Line 1: Line 1:
 +====== Export Layer Objects ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //How to export all objects by layer, with each layer exported to a new file.//
 +
 +===== Example =====
 +The following RhinoScript demonstrates how to export all objects by layer, with each layer exported to a new file.
 +
 +<code vb>
 + ​Option Explicit
 +
 + Sub ExportLayerObjects
 +
 +   '​ Declare local variables
 +   Dim strPath, strFile
 +   Dim arrLayers, strLayer
 +   Dim arrSelected
 +
 +   '​ Get the path to and name of the current document.
 +   '​ Surround with double-quotes in case path includes spaces.
 +   ​strPath = Chr(34) & Rhino.DocumentPath & Rhino.DocumentName & Chr(34)
 +
 +   '​ Get names of all layers
 +   ​arrLayers = Rhino.LayerNames
 +
 +   '​ Disable redrawing
 +   ​Rhino.EnableRedraw False
 +
 +   '​ Process each layer
 +   For Each strLayer In arrLayers
 +
 +     '​ Unselect all   
 +     ​Rhino.Command "​_-SelNone",​ 0
 +
 +     '​ Select all objects on layer. Surround layer name
 +     '​ with double-quotes in case it includes spaces.
 +     ​Rhino.Command "​_-SelLayer " & Chr(34) & strLayer & Chr(34), 0
 +
 +     '​ Make sure some objects were selected
 +     ​arrSelected = Rhino.SelectedObjects
 +     If IsArray(arrSelected) Then
 +
 +       '​ Generate a modified path string
 +       '​ that includes the layer name
 +       ​strFile = strPath
 +       ​strFile = Replace(strFile,​ "​.3dm",​ "​_"​ & strLayer & "​.3dm"​)
 +
 +       '​ Export the selected objects
 +       ​Rhino.Command "​_-Export " & strFile, 0
 +
 +     End If
 +   Next
 +
 +   '​ Unselect all
 +   ​Rhino.Command "​_-SelNone",​ 0
 +
 +   '​ Enable redrawing
 +   ​Rhino.EnableRedraw True
 +
 + End Sub
 +
 +</​code>​
 +The script can be altered to export different filetypes: change "​strFile = Replace(strFile,​ "​.3dm",​ "//​_"​ & strLayer & "​.3dm"​)"​ to "​strFile = Replace(strFile,​ "​.3dm",​ "//​_"​ & strLayer & "​.xxx"​)"​ where xxx is the desired filetype extension. Do not forget to update the script name in the second line (e.g. "Sub ExportLayerObjectsIGES"​).
 +
 +
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/exportlayerobjects.txt ยท Last modified: 2015/09/14 (external edit)