One thing is the:
id0 = Rhino.ObjectsByLayer("Source", True)
will always return an array, even if there is only one object on that layer.
So if you try this:
xf0 = rhino.BlockInstanceXform(id0)
you get an error because you feed an array where it expects a string (objectID)
so you would need to do:
xf0 = rhino.BlockInstanceXform(id0(0))
to get 1st element of the array, or iterate through all objects in the returned array if there is more on that layer.
hope that makes sense. I didn’t test or look at the rest. this is the first thing that jumped at me.