I am using a python script, which opens an mxd, loads a feature class, exports the map to a png. That script produces a few hundreds of maps. After my update to 10.4 (maybe that is a coincidence) the north arrow changes the position. On some maps it is in the right position, sometimes a bit right or left from the correct position and sometimes not on the map at all. Is there any explanation for that? How can I prevent that from happening? My script is not touching the north arrow.
Ok, I could break down the code to 47 lines. It is still to much, but I don't know what else I can leave out. I have one mxd and one feature class with two fields. One field speciefies the species and one the Date. The script prints maps of all species at the first date than maps of all species at the second date a.s.o.
The scipt prints the first 48 maps (all 24 species at the first and second date) correct. After that the north arrow starts to move in a loop. It is never at the same position. After 22 more maps the north arrow has left the map completly. However, with another dataset, the values are 45 and 5 and the north arrow moves into another direction.
import arcpy,datetime,os arcpy.env.overwriteoutput = True mxd = r"C:/GIS/Project.mxd" fc = r"X:/GIS/data.gdb/grid" field = "Species" datefield = "Season" output = r"X/GIS/TEST" printresulution = 150 def multiMap(mxd,fc,field,datefield,output,printresulution): mxd2 = mxd mxd = arcpy.mapping.MapDocument(mxd2) data_frame = arcpy.mapping.ListDataFrames(mxd) layer = arcpy.mapping.Layer(fc) layername = layer.name specieslist =  datelist =  cursor = arcpy.SearchCursor(fc) for row in cursor: if row.getValue(field) not in specieslist: specieslist.append(row.getValue(field)) if row.getValue(datefield) not in datelist: datelist.append(row.getValue(datefield)) counter = 0 for tag in range(0,len(datelist)): counter += 1 for specie in range(0,len(specieslist)): where_clause = "%s = '%s' AND %s = '%s'" % (field,specieslist[specie],datefield,datelist[tag]) layer.definitionQuery = where_clause for lyr in arcpy.mapping.ListLayers(mxd, "Raster_grouplayer",arcpy.mapping.ListDataFrames(mxd)): arcpy.mapping.AddLayerToGroup(arcpy.mapping.ListDataFrames(mxd),lyr,layer,"TOP") mxd.save() layer.visible = True arcpy.RefreshTOC() arcpy.mapping.ExportToPNG(mxd, output + os.sep + specieslist[specie].replace(".","").replace(r"/","_").replace(",","_") + "_" + str(counter) + "_" + datelist[tag].replace(".","").replace("/","").replace(" ","_") + r".png",resolution=printresulution) mxd.save() del data_frame,mxd mxd = arcpy.mapping.MapDocument(mxd2) data_frame = arcpy.mapping.ListDataFrames(mxd) layerlist = arcpy.mapping.ListLayers(mxd,"",data_frame) for element in layerlist: if element.name == layername: arcpy.mapping.RemoveLayer(data_frame,element) mxd.save() mxd = arcpy.mapping.MapDocument(mxd2) mxd.save() multiMap(mxd,fc,field,datefield,output,printresulution)
One more edit: I don't really to save the mxd and maybe there is the mistake. However, I would like to keep the possibility to change the map and save these changes. That is why I kept it in the snippet.