Select to view content in your preferred language

Export Page Layout to PNG, type 'exceptions.AssertionError'

1205
4
Jump to solution
04-11-2013 06:54 AM
MatthewPeters
Occasional Contributor
I'm using ArcGIS 10.0 sp5 on a Win7 PC and need help with a script to turn layers on/off and export the page layout to an image file. The script works until the ExportToPNG(). I have 281 layers with up to 10 attributes I have to map (static extent) so scripting the arduous task of changing each layers visibility is preferred. I have a VBA tool to change the symbology between the 10 attributes of selected layers and now I'd like to take advantage of the arcpy.mapping functionalities.

import os, sys, string, arcpy  # define list of species spLst = ['0070','1320']  try:     mxd = arcpy.mapping.MapDocument(r"C:/Workspace/Species.mxd")      # check for broken paths     brknList = arcpy.mapping.ListBrokenDataSources(mxd)     if len(brknList) >= 1:         print "Broken Paths Exist..." + brknList     else:         for sp in spLst:             print "No broken paths, proceeding"             lyrName = "ew20km_in" + str(sp) + "_2040"                          lyrList = arcpy.mapping.ListLayers(mxd, lyrName)                          for lyr in lyrList:                                  # define variables                 out_png1 = r"C:/Workspace/pixels_500/rfbird_" + str(sp) + "_2040.png"                 out_png2 = r"C:/Workspace/pixels_800/rfbird_" + str(sp) + "_2040.png"                 resolution1 = 45                   resolution2 = 72                                  lyr.visible = True # make layer visible, all other species should start as invisible                                  arcpy.RefreshTOC()                 arcpy.RefreshActiveView()                                  # export current layout view to png file                 # ExportToPNG (map_document, out_png, {data_frame}, {df_export_width}, {df_export_height}, {resolution}, {world_file}, {color_mode}, {background_color}, {transparent_color}, {interlaced})                                  arcpy.mapping.ExportToPNG(mxd, out_png1, "PAGE_LAYOUT", "", "", resolution1, "", "24-BIT_TRUE_COLOR", "", "", "")                 arcpy.mapping.ExportToPNG(mxd, out_png2, "PAGE_LAYOUT", "", "", resolution2, "", "24-BIT_TRUE_COLOR", "", "", "")                                  lyr.visible = False  except:     arcpy.AddMessage(arcpy.GetMessages(2))     print arcpy.GetMessages (2)     print "Exited with Errors.... Something is wrong"     
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JimCousins
MVP Alum
Matt,
The error is in your ExportToPNG argument - you need keyword "resolution" in there. Also, 24 bit true color is the default, so drop the arguments after the resolution to simplify things.
Try:
arcpy.mapping.ExportToPNG(mxd, out_png1, "PAGE_LAYOUT", resolution=resolution1)

Regards,
Jim

View solution in original post

0 Kudos
4 Replies
JimCousins
MVP Alum
Matt,
The error is in your ExportToPNG argument - you need keyword "resolution" in there. Also, 24 bit true color is the default, so drop the arguments after the resolution to simplify things.
Try:
arcpy.mapping.ExportToPNG(mxd, out_png1, "PAGE_LAYOUT", resolution=resolution1)

Regards,
Jim
0 Kudos
MatthewPeters
Occasional Contributor
Thanks Jim,

That seemed to fix the error. I didn't realize that some parameters require keywords even when setting up the place holders for all parameters within a function.
0 Kudos
JeffBarrette
Esri Regular Contributor
Arcpy.mapping parameters can't be skipped with empty quotes.  In Python, if you want to skip parameters, you must call out the parameter name and set it appropriately.  Once you do that, all subsequent parameters must be set the same way.

Jeff
0 Kudos
MatthewPeters
Occasional Contributor
Arcpy.mapping parameters can't be skipped with empty quotes.  In Python, if you want to skip parameters, you must call out the parameter name and set it appropriately.  Once you do that, all subsequent parameters must be set the same way.

Jeff


Forgive me, as I'm not a programmer and my experience comes from coding with ArcGIS 9.x, but that seems to be inconsistant. Within my code I have defined variables for the first three parameters and don't specifically call them (i.e., map_document = mxd, out_png = out_png1, {data_frame} = "PAGE_LAYOUT"). The original code used empty quotes so that I wouldn't be skipping parameters, but keeping optional parameters blank. The sixth parameter I did want to set, but to get it to work I needed to call the parameter by name like Jim and you have indicated.

So that I understand the logic better, why is it not required to call the first three parameters when setting their values? Is it becasue parameters 1 and 2 are required and 3 on are optional?
0 Kudos