Agrupación de Objetos en Rhino
Un bloque por capa – RhinoScripting
Ayer por la tarde, estábamos exportando un modelo de Rhino (que contiene principalmente mallas) a SketchUp. Utilizamos DWG como formato de traducción y el modelo resultante era una sopa de triángulos, así que pensamos que sería una buena idea cada capa del modelo de Rhino en un bloque para que SketchUp lo convirtiera en un componente.
Esto aislaría a los bordes de todos los objetos de los de otras capas y haría la selección más cómoda. En lugar de pasar 10 minutos convirtiendo a mano cada una de las 20 capas de nuestro archivo, pensamos que podríamos escribir un script para hacerlo. Al final nos llevó más de lo esperado pues mi RhinoScripting está un poco (tal vez mucho) oxidado.
Aquí tienes el código comentado en inglés, si quieres puedes directamente descargar el archivo.
Option Explicit
'Script written by Roberto Molinos @robertomolinos
'Script copylefted by Modelical // free to use, improve and share
'Script version Friday, 21 March 2014 19:58:18
Call Layers2Blocks()
Sub Layers2Blocks()
Dim strFile
Dim arrLayers, strLayer, strBlock
Dim arrSelected, arrPoint
' 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
'Create insertion point at 0,0,0
arrPoint = Array(0, 0, 0)
'Set current layer so block is created on the same one
Call Rhino.CurrentLayer(strLayer)
'Create block
strBlock = Rhino.AddBlock(arrSelected, arrPoint, strLayer, True)
'Delete objects as they are now in the block
Call Rhino.DeleteObjects(arrSelected)
'Insert the block
Call Rhino.InsertBlock(strBlock, arrPoint)
End If
' Unselect all
Rhino.Command "_-SelNone", 0
Next
' Unselect all
Rhino.Command "_-SelNone", 0
' Enable redrawing
Rhino.EnableRedraw True
End Sub
Este post y el código se basa en un artículo en la Wiki de McNeel – ExportLayerObjects