Editing body properties (name and tree structure) on Parasolid Exports!

Hello,

I have some files I need to export as parasolid, it is a lot of files, with a lot of bodies. But I would like to edit the Bodies name, right know the parasolid exporter writes with filename_bodyID, what I would like to do is exporting it as Layer_bodyName.

Ever better would be if I could rename the bodies as Layer_bodyName and use the python script export by Layer that I found on the forum :slight_smile:

Or, even even better, with a different approach, would be if I could export what paraSolid understands as sub-assembly
Like
Filename
-------- Layer
------------partName1
------------partName2
----------Layer2
------------partName3
------------subLayer1
----------------partName4

If somehow I could make the tree structure on the paraSolid export, would be a game changer! But the first solution would also help a lot

What I managed to do so far to do what I need is, using the Python Script exporting as STL with the filename = layer name (making all bodies in the layer as a singles file) just because the STL import on the other software I need to use keeps the file name as reference (JT2GO)

Thanks

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.

Maybe I could try to reverse the ExplodeBlocksToLayers command

@pascal do you think that would be possible? for me to reverse reverse engineer your python code?