I have a Rhino file with a lot of layers. Each layer includes surfaces which needs to be joined. This task takes some time, because I need to go through every layer and join the surfaces separately.
Is there a way to just select the whole model and have a routine which joins the surfaces layer by layer.
The expected result is that the surfaces from a layer are joined but not joint to the surfaces form the other layers.
By the way this question is not related to my “Mesh topology across polysurfaces?” topic.
Here is a quick hack… Actually this also joins curves and meshes. Hang on a bit…
Script gives you choice of what types of objects you want to join, remembers your choice within the same session.
One more edit: added the possibility to select a range of layers, not just all layers…
–Mitch
"""Joins curves, surfaces/polysurfaces, meshes by layer.
Choice of object type and layer range. Script by Mitch Heynick 08.04.15"""
import rhinoscriptsyntax as rs
import scriptcontext as sc
def DoJoin(objs):
rs.SelectObjects(objs)
rs.Command("_Join",False)
rs.UnselectAllObjects()
def JoinByLayerWithChoice():
#Get previous settings
if "JBL_Crvs" in sc.sticky: crv_x = sc.sticky["JBL_Crvs"]
else: crv_x = True
if "JBL_Srfs" in sc.sticky: srf_x = sc.sticky["JBL_Srfs"]
else: srf_x = True
if "JBL_Meshes" in sc.sticky: mesh_x = sc.sticky["JBL_Meshes"]
else: mesh_x = True
if "JBL_LayerChoice" in sc.sticky: lay_x = sc.sticky["JBL_LayerChoice"]
else: lay_x = True
items=["Curves","Surfaces","Meshes"]
choice=[(items[i],"No","Yes") for i in range(3)]
choice.append(("LayerRange","AllLayers","Select"))
gb=rs.GetBoolean("Items to join?",choice,[crv_x,srf_x,mesh_x,lay_x])
if gb and (gb[0]+gb[1]+gb[2]+gb[3])>0:
if gb[3]:
layers=rs.GetLayers("Select layers to join objects")
if not layers: return
else:
layers=rs.LayerNames()
rs.EnableRedraw(False)
rs.UnselectAllObjects()
for layer in layers:
objs=rs.ObjectsByLayer(layer)
if objs:
crvs=[] ; srfs=[] ; meshes=[]
for obj in objs:
if rs.IsCurve(obj):
crvs.append(obj)
elif rs.IsBrep(obj) and not rs.IsObjectSolid(obj):
srfs.append(obj)
elif rs.IsMesh(obj):
meshes.append(obj)
if gb[0] and len(crvs)>1: DoJoin(crvs)
if gb[1] and len(srfs)>1: DoJoin(srfs)
if gb[2] and len(meshes)>1: DoJoin(meshes)
else: return
#Set preferences
sc.sticky["JBL_Crvs"] = gb[0]
sc.sticky["JBL_Srfs"] = gb[1]
sc.sticky["JBL_Meshes"] = gb[2]
sc.sticky["JBL_LayerChoice"] = gb[3]
JoinByLayerWithChoice()