Setting layer "states" of block instances

So basically the functionality I’m looking for is to be able to use a single block instance, for example, a “generic” door.

So kindof have one block with layers for open/closed, hinge side left right/ various jamb thicknesses, windows/no window panels etc.

So then somehow code the state of each door and put the string in the instance name?

Then the script would read the name, decode it, and set the layers accordingly.

Is this at all possible? Can you toggle layer visibility inside linked blocks via script?

Hi wynott,

Late reply, but this this get you along?:

import rhinoscriptsyntax as rs

def Main():
    obj = rs.GetObject('get block')
    if not obj: return
    if not rs.IsBlockInstance(obj): return
    
    # get block name of the instance
    block_name = rs.BlockInstanceName(obj)
    # get objects from this block definition
    block_objects = rs.BlockObjects(block_name)
    block_layers = [rs.ObjectLayer(block_obj) for block_obj in block_objects]
    print block_layers
    # purge duplicates
    block_layers = list(set(block_layers))
    
    
    #get the instance name
    instance_name = rs.ObjectName(obj)
    if not instance_name : return
    
    for layer in block_layers:
        block_layer_basename = layer.split('::')[-1]
        print block_layer_basename
        if instance_name == block_layer_basename:
            rs.LayerVisible(layer,visible=True)
        else:
            rs.LayerVisible(layer,visible=False)
    
    
    

Main()