Ok, so after some testing, I found out that Blocks can simulate what I need to do
Creating Blocks inside Blocks simulate the tree structure when importing into NX
So I tried my first time with python inside rhino to try to convert each layer into a block, but I got stuck, it worked fine to create the block to the lowest sublayer but I think i failed in my logic on how to do it.
Btw I Frankstein my way out it using an ExportByLayer script I found around the discourse, the reason why there is a comment folder selection is that I intend to make it export the resulting file in the end.
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
import System
import os
def SelectObjectTypes(objs):
for obj in objs:
otype=rs.ObjectType(obj)
if otype==8 or otype==16 or otype==4096 or otype==1073741824:
rs.SelectObject(obj)
def BatchBlockByLayer():
# doc_name=sc.doc.Name
# ft="STP"
# filt = "{} Files (*.{})|*.{}||".format(ft,ft.lower(),ft.lower())
# if not doc_name:
# #document hasn't been saved
# msg="Main file name/folder for {} export?".format(ft)
# filename=rs.SaveFileName(msg, filt)
# #SaveFileName returns the complete path plus file name
# if filename==None: return
# else:
# #document has been saved, get path
# msg="Folder for {} export? (Enter to save in current folder)".format(ft)
# folder = rs.BrowseForFolder(rs.WorkingFolder(), msg)
# if not folder: return
# filename=os.path.join(folder,doc_name)
#start the export sequence
rs.EnableRedraw(False)
layers=rs.LayerNames()
for layer in layers:
if rs.IsLayerSelectable(layer):
#need to check for sublayers in name and replace "::"
#layer_name=layer.replace("::","_")
cutNameArray = layer.split("::")
cutName = cutNameArray[len(cutNameArray)-1]
blockName = cutName
# e_file_name = '"{}-{}.{}" '.format(filename[:-4],layer_name,ft.lower())
rs.UnselectAllObjects()
objs=rs.ObjectsByLayer(layer, False)
SelectObjectTypes(objs)
# --------------------- Preciso Converter isso em criar o Bloco ----------------------
if rs.SelectedObjects():
# #runs the export using the file name/path and your settings
rs.CurrentLayer(layer)
block = rs.AddBlock(objs, (0,0,0), blockName, True)
rs.InsertBlock(block, (0,0,0))
# rs.Command("-_Export "+e_file_name+" _Enter", False)
rs.EnableRedraw(True)
BatchBlockByLayer()
Could someone give me some help on the recursive part of the logic, so the code runs multiple times to create blocks with blocks until there is just one block left?
My Structure of the layer tree simulates the structure of an assembly.
Main Layer
Sub 1
Sub 1.1
Sub 1.2
Sub 1.2.1
Sub 2
Sub 2.1
Sub 2.2
Sub 3
and so on...
Thanks in advance.