Please Help I'm trying to align and lock piles to reference planes using dynamo

I’ve written a script which allow me to align and lock multiple piles to reference planes, there seems to be a problem however, in that it allow me to align and lock the piles to vertical reference planes without a problem but will only align the piles to the horizontal refence planes but fails on the locking. Can anyone shed some light as to why this fails please.

This is what I’m trying to achieve where the piles will be pulled onto the relevant plane and then be locked to it.

This is the python script for locking the piles to the reference planes

Align and lock SDR1.dyn (32.7 KB)

This is the error that’s reported

Any help to solve this would be most welcome.