Issue: layer attribute lost with rs.TransformObjects() on linked blocks

Hi There,

There’s an issue with rs.TransformObjects() on referenced geometry. I use a script to recursively get all containing geometry from a block (in main.3dm), with nested linked blocks inside.

I expect the copied geometry to be in the same layer as the original geometry. However, the layer is lost and the the currently active layer is assigned. Please see video, demo script and files below.



linked_block.3dm (156.8 KB)
main.3dm (66.2 KB)

# coding=utf-8
import rhinoscriptsyntax as rs

def traverse(instance, func, results = None, parent_xform = rs.XformIdentity()):
    if results is None:
        results = []

    xform = rs.BlockInstanceXform(instance)
    block_name = rs.BlockInstanceName(instance)

    content = rs.BlockObjects(block_name)
    for item in content:

        func(item, xform, results)

        if rs.IsBlockInstance(item):
            parent_xform = parent_xform * xform
            traverse(item, func, results, parent_xform=parent_xform)
    return results

# for each leaf, create a copy using rs.TransformObjects()
def copy_geom(item, parent_xform, results):
    if rs.IsBlockInstance(item):

    transformed_copy = rs.TransformObject(item, parent_xform, copy=True)
    print(rs.ObjectLayer(item), rs.ObjectLayer(transformed_copy))

def main():
    # select a block instance
    instance = rs.GetObject(preselect=True, filter=rs.filter.instance)

    # traverse the tree inside the selected instance
    # execute "copy_geom" on each leaf
    results = traverse(instance, copy_geom)
    # move results aside for clarity
    rs.MoveObjects(results, (0,100,0))

if __name__ == '__main__':