I'm working on a project that utilizes ArcPy to join a shapefile and a excel file. This join takes information from the excel file and creates a map that highlights certain areas different shades of a color to display the data in a more visually concise format.
I start with a blank map file, and place the shapefile and the excel file into the file as layers. The join works perfectly with no errors; however, when I go to save the map file as a copy, and then subsequently export a pdf of the output, I get blank files both times.
I call arcpy.RefreshTOC() and arcpy.RefreshActiveView() to attempt to make my changes refresh onto the map, but nothing happens.
Here is my code:
import arcpy
# setup workspace
env.workspace = r"C:\Users\Class\Desktop\MapCreation\Resources"
env.qualifiedFieldNames = False
# start work on blank map
mapFile = r'C:\Users\Class\Desktop\MapCreation\Resources\blankMap.mxd'
mxd = arcpy.mapping.MapDocument(mapFile)
# create a table view from the xls
table = arcpy.mapping.TableView(r'C:\Users\Class\Desktop\MapCreation\Resources\2012tpreg.xls\teens$')
# create a new layer using shapefile
shape_file_layer = arcpy.MakeFeatureLayer_management(r'C:\Users\Class\Desktop\MapCreation\Resources\MSshapefiles\MScounties.shp')
# AddJoin
arcpy.AddJoin_management(shape_file_layer, "CNTY_FIPS", table, "FiPS")
# refresh the TOC and ActiveView in order to propagate the changes
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
# export PDF
mxd.saveACopy(r'C:\Users\Class\Desktop\MapCreation\Resources\newMap.mxd')
arcpy.mapping.ExportToPDF(mxd, "test.pdf")
I should note that I know the join is working correctly, because when I run that piece code inside the ArcGIS environment (rather than in IDLE or Command Prompt) it creates the join as a layer in the map environment.
I have tried a lot of different ideas to try to get this problem fixed and I couldn't figure out anything that helped. If anyone has any ideas on what could be wrong I would love to hear them.