Export MXD to pdf script crashing ArcCatalog

447
3
02-09-2018 12:58 PM
RayGreen
New Contributor II

I am kind of new to anything Python and was using the Basic Printing tutorial script from ESRI, but when I try and run it it works for a while and then

my entire ArcCatalog crashes and asks if I would like to send a report.  It is just the following code:

 

import arcpy
import os
import uuid

# Input WebMap json
Web_Map_as_JSON = arcpy.GetParameterAsText(0)

# The template location in the server data store
templateMxd = r"c:\test\Template.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]

# Remove the service layer
# This will just leave the vector layers from the template
for lyr in arcpy.mapping.ListLayers(mxd, data_frame=df):
if lyr.isServiceLayer:
arcpy.mapping.RemoveLayer(df, lyr)

arcpy.env.scratchWorkspace = 'c:/Temp'

# Use the uuid module to generate a GUID as part of the output name
# This will ensure a unique output name
output = 'WebMap_{}.pdf'.format(str(uuid.uuid1()))
Output_File = os.path.join(arcpy.env.scratchFolder, output)

# Export the WebMap
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)

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

what did you provide to GetParameterAsText(0) ?

For code formatting see Code formatting... the basics++

0 Kudos
RayGreen
New Contributor II

I set it up in ArcCatalog as shown above.

0 Kudos
RayGreen
New Contributor II

Well I just changed it to an mxd with just a point layer in it as a test and it ran fine, I will have to see what is in the mxd that is causing it to crash.  Thanks for the response Dan, if I figure out what is going on with the original mxd causing the crash I will respond here.