Is it possible that some of yours
graphics aren't .psd or .pdf type?
Changing a layer invalidates the entire graphics set, so you cannot rely on the value of any of your (cached!) variables.
I can see that the code is working when integrated into my script, but I don't understand why it's working. Any explanation you can provide is greatly appreciated, or can you point me in the right direction to read up? (I'm a newbie).
I guess I was using cached variables?
The solution you provided, does it use a specific programming concept I can research more?