Hello,
For your script to work, it needs to run a simulation on a case that you set up with self shading enabled with the "Thin file (linear)" option on the Shading and Snow input page. You will also need to make sure that the number of modules along side and bottom of row inputs result in an array with more than one row.
Before you run your script, set the case up in SAM and run a simulation by clicking the Simulate button to make sure it is generating reasonable self shading results. Then try running your script.
If you continue to have trouble, please attach a copy of your .sam file and .lk file to your original post above (edit it to add an attachment) or use the website Contact form to email it to me.
Best regards,
Paul.