Select to view content in your preferred language

Is there a easy way to Export a MXD with a lot of SDE connections?

582
0
05-15-2012 09:42 AM
ShaneHelm
Deactivated User
I have a simple script that exports a map to a JPEG. Here is the meat of it:


print "generating ouput of " + mxdPath
mxd = arcpy.mapping.MapDocument(mxdPath)

arcpy.mapping.ExportToJPEG(mxd, outputPath, 'PAGE_LAYOUT',1024,1024)



Pretty easy. Problem is there is a ton of SDE Connections, that in turn throw a "Spatial Connection Dialog" that stalls the script. I found a blog or a forum post that said if I use the "CreateArcSDEConnectionFile_management" GP to create the .sde files before I tried exporting the jpeg, I wouldn't get the Spatial Connection Dialog. Seemed to work ok but the problem is every time I run this script i need to create some 10 .sde connection files for the different SDE servers.

# create temporary connection files in memory
print "create ArcSDE Connection files"
try:
    print 'created'
    arcpy.AddMessage('create connections')
    arcpy.CreateArcSDEConnectionFile_management( sdeConnectionFolder, "Connection1", "Server1", "5161", "", "DATABASE_AUTH", "[USERNAME]", "[password]", "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION")
    arcpy.CreateArcSDEConnectionFile_management( sdeConnectionFolder, "Connection2", "Server2", "5161", "", "DATABASE_AUTH", "[USERNAME]", "[password]", "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION")
    arcpy.CreateArcSDEConnectionFile_management( sdeConnectionFolder, "Connection3", "Server3", "5161", "", "DATABASE_AUTH", "[USERNAME]", "[password]", "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION")
    arcpy.CreateArcSDEConnectionFile_management( sdeConnectionFolder, "Connection4", "Server4", "5161", "", "DATABASE_AUTH", "[USERNAME]", "[password]", "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION")
    arcpy.CreateArcSDEConnectionFile_management( sdeConnectionFolder, "Connection5", "Server5", "5161", "", "DATABASE_AUTH", "[USERNAME]", "[password]", "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION")
    arcpy.CreateArcSDEConnectionFile_management( sdeConnectionFolder, "Connection6", "Server6", "5161", "", "DATABASE_AUTH", "[USERNAME]", "[password]", "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION")
    arcpy.CreateArcSDEConnectionFile_management( sdeConnectionFolder, "Connection7", "Server7", "5161", "", "DATABASE_AUTH", "[USERNAME]", "[password]", "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION")
    arcpy.CreateArcSDEConnectionFile_management( sdeConnectionFolder, "Connection8", "Server8", "5161", "", "DATABASE_AUTH", "[USERNAME]", "[password]", "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION")
    arcpy.CreateArcSDEConnectionFile_management( sdeConnectionFolder, "Connection9", "Server9", "5161", "", "DATABASE_AUTH", "[USERNAME]", "[password]", "SAVE_USERNAME", "SDE.DEFAULT", "SAVE_VERSION")



except Exception as e:
    print e.message

    # If using this code within a script tool, AddError can be used to return messages
    #   back to a script tool.  If not, AddError will have no effect.
    arcpy.AddError(e.message)

print "generating ouput of " + mxdPath
mxd = arcpy.mapping.MapDocument(mxdPath)

arcpy.mapping.ExportToJPEG(mxd, outputPath, 'PAGE_LAYOUT',1024,1024)



This works OK, but is slow when I run through 100 maps as I have to run them one at a time. Is there a better way to do this? Is there a way for me to create these .sde connection files, and in the script somehow reference them?



Cheers
Tags (2)
0 Kudos
0 Replies