Skip to content

Instantly share code, notes, and snippets.

@slibby
Created August 19, 2015 15:15
Show Gist options
  • Save slibby/28af9566fc336c498154 to your computer and use it in GitHub Desktop.
Save slibby/28af9566fc336c498154 to your computer and use it in GitHub Desktop.
Print task which replaces HTTPS FQDN URLs with http://ip
import arcpy
import os
import uuid
# Input WebMap json
Web_Map_as_JSON = arcpy.GetParameterAsText(0)
Web_Map_as_JSON = Web_Map_as_JSON.replace("https://FQDN","http://localIP")
# The template location in the server data store
template = arcpy.GetParameterAsText(2)
if "Landscape" in template:
templateMxd = r'C:\Program Files\ArcGIS\Server\Templates\ExportWebMapTemplates\A3 Landscape.mxd'
else:
templateMxd = r'C:\Program Files\ArcGIS\Server\Templates\ExportWebMapTemplates\A3 Portrait.mxd'
# Convert the WebMap to a map document
result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON, templateMxd)
mxd = result.mapDocument
# Reference the data frame that contains the webmap
# Note: ConvertWebMapToMapDocument renames the active dataframe in the template_mxd to "Webmap"
df = arcpy.mapping.ListDataFrames(mxd, 'Webmap')[0]
# Use the uuid module to generate a GUID as part of the output name
# This will ensure a unique output name
format = arcpy.GetParameterAsText(1)
if format == "PNG":
output = 'WebMap_{}.png'.format(str(uuid.uuid1()))
else:
output = 'WebMap_{}.pdf'.format(str(uuid.uuid1()))
Output_File = os.path.join(arcpy.env.scratchFolder, output)
# Export the WebMap
if format == "PNG":
arcpy.mapping.ExportToPNG(mxd, Output_File)
else:
arcpy.mapping.ExportToPDF(mxd, Output_File)
# Set the output parameter to be the output file of the server job
arcpy.SetParameterAsText(1, Output_File)
# Clean up - delete the map document reference
filePath = mxd.filePath
del mxd, result
os.remove(filePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment