Loop AddLayers and Add Title - Dynamic Titles aren't correct

Discussion created by lbarry78 on Oct 28, 2011
I received some help from a kind forum user to help me over a stumbling block with a piece of looping code which I then added to. My problem now lies with the additional code. The code runs through the layers and outputs as Tiff etc. to output folder.
Upon verification however I've noticed that there are 524 input layers but only 480 output images. The output maps and the text on the maps are out of sync. Some of the data layers do not match up to the text title (TEXT_ELEMENT=Species) (they are quite often one layer out while others are correct.
I have attached the code.
I am confused. I have considered a few possible causes - slow refresh (but I've added in a couple of extra view refreshes), longer layer names (none are beyond 30 characters) or the fact that the second layer added in is given the addition of _Layer1 instead of _Layer. Or it could be something else - I'm not sure.
Any thoughts on this are really appreciated