While we import the AutoCAD file to Rhino, the nested blocks (or sub-blocks) are always painful to deal with, especially they would mess up your layer structure in Rhino. Of course, you may explode the blocks, again and again, to change their layers. There is an easy solution for you to keep the block property, meanwhile, assign the blocks and nested blocks in the desired layer.
The thread in the following link provides a solution, here. To make the script more efficient, I edit a little bit of the code that ensures all the blocks instance will automatically be re-assigned to the designated layer.
You may find the download package here.
Following are the code with simple explanation.
import rhinoscriptsyntax as rs import scriptcontext as sc import Rhino def MoveBlockObjectsToLayer(): ids = rs.BlockInstances(blk,0) #assign the block that want to modify if not ids: return targ = rs.LayerId(layer) #assign the layer that want to change to if not targ: return names = list(set([rs.BlockInstanceName(id) for id in ids])) #set method to remove the duplicate instances(ID) done = [] def BlockDrill(names): while True: if len (names) > 0 : name = names.pop() else: break done.append(name) temp = rs.BlockObjects(name) #Returns identifiers of the objects that make up a block definition rs.ObjectLayer(temp, targ) # if there r nested block for tempId in temp: if rs.IsBlockInstance(tempId): tempName = rs.BlockInstanceName(tempId) if tempName not in names and tempName not in done: names.append(tempName) BlockDrill(names) BlockDrill(names) if clean: sc.doc =Rhino.RhinoDoc.ActiveDoc blks = rs.BlockNames() for blk in blks: MoveBlockObjectsToLayer() rs.ObjectLayer(rs.BlockInstances(blk), blklayer) blocks = blks sc.doc = ghdoc