Interesting, I just tried running the script that yesterday was throwing an exception when assigning to little 'r' reference in a newly opened PhotoScan instance and it worked perfectly.
The script and data set had not changed at all. The only thing that changed was that my dev machine had been rebooted and the PhotoScan instance was newly launched. The PhotoScan instance I was testing in yesterday was 'dirty' in the sense that it had been used to test several other things by running scripts and executing commands at the console. Each time I ran the test script though I was creating a new project from the File menu to run it in. So, as James observed, some intermittent interaction seems to have been happening. I'll keep an eye on it and see if I can reproduce inorder to narrow down the cause further.
As an aside, just going by this discussion, it seems like having both Scalebar.reference and Scalebar.Reference is a bit dangerous.