Copy nested blocks in place -- python

i’m trying to copy out the nested blocks but having trouble getting them back in their instance locations, they go back to 0. Do i need to create a plane at their instance origin and do plane to plane transformation? It seems to hold some sort of relation to the Top Level Block.

My attempts so far.

import rhinoscriptsyntax as rs
import Rhino


#Select Block
#Get all instances of block
#Explode and get 1st level nested blocks
#place instance of said block at its locations

selBlks = rs.GetObjects("Select Blocks", 4096)
blkcpy = []

for blk in selBlks:
    name = rs.BlockInstanceName(blk)
    allBlks = rs.BlockInstances(name)
    for bk in allBlks:
        blkObjs = rs.BlockObjects(rs.BlockInstanceName(allBlks[0]))
        for blkblk in blkObjs:
            if rs.IsBlockInstance(blkblk):
                blkcpy.append(blkblk)

rs.CopyObjects(blkcpy)
print blkcpy

import rhinoscriptsyntax as rs
import Rhino


#Select Block
#Get all instances of block
#Explode and get 1st level nested blocks
#place instance of said block at its locations

selBlks = rs.GetObjects("Select Blocks", 4096)

for blk in selBlks:
    name = rs.BlockInstanceName(blk)
    allBlks = rs.BlockInstances(name)
    for bk in allBlks:
        blkObjs = rs.BlockObjects(rs.BlockInstanceName(allBlks[0]))
        bkx = rs.BlockInstanceXform(bk)
        for blkblk in blkObjs:
            if rs.IsBlockInstance(blkblk):
                xform = rs.BlockInstanceXform(blkblk)
                bname = rs.BlockInstanceName(blkblk)
                #needs transformation of bkx to xform
                #insrtbk = rs.InsertBlock2(bname, bkx)
            

something like this?

import rhinoscriptsyntax as rs
import Rhino


#Select Block
#Get all instances of block
#Explode and get 1st level nested blocks
#place instance of said block at its locations

selBlks = rs.GetObjects("Select Blocks", 4096)
blkcpy = []

for blk in selBlks:
    name = rs.BlockInstanceName(blk)
    xform = rs.BlockInstanceXform(blk)
    allBlks = rs.BlockInstances(name)
    for bk in allBlks:
        blkObjs = rs.BlockObjects(rs.BlockInstanceName(allBlks[0]))
        for blkblk in blkObjs:
            if rs.IsBlockInstance(blkblk):
                blkcpy.append(blkblk)

new = rs.CopyObjects(blkcpy)
rs.TransformObjects(new, xform, False)

ooh, ok. Thats much easier than the route i was heading. Thanks!

i just had to change the scope a bit to get the right xform.

import rhinoscriptsyntax as rs
import Rhino


#Select Block
#Get all instances of block
#Explode and get 1st level nested blocks
#place instance of said block at its locations

selBlks = rs.GetObjects("Select Blocks", 4096)


for blk in selBlks:
    blkcpy = []
    name = rs.BlockInstanceName(blk)
    xform = rs.BlockInstanceXform(blk)
    allBlks = rs.BlockInstances(name)
    for bk in allBlks:
        blkObjs = rs.BlockObjects(rs.BlockInstanceName(allBlks[0]))
        for blkblk in blkObjs:
            if rs.IsBlockInstance(blkblk):
                blkcpy.append(blkblk)

    new = rs.CopyObjects(blkcpy)
    rs.TransformObjects(new, xform, False)