Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I use this script right now:

import os, arcpy

directory = r"C:\Project"
 for root, dirs, files in os.walk(directory):
  for myFile in files:
    fileExt = os.path.splitext(myFile)[1]
    if (fileExt == ".mxd"):
        fullPath = os.path.join(root, myFile)
        print myFile

        myMap = arcpy.mapping.MapDocument(fullPath)
        analysis = arcpy.mapping.AnalyzeForMSD(myMap)

for key in ('messages', 'warnings', 'errors'):
print "----" + key.upper() + "---"
vars = analysis[key]
for ((message, code), layerlist) in vars.iteritems():
print "    ", message, " (CODE %i)" % code
print "       applies to:",
for layer in layerlist:
print layer.name,
print

It runs on many project mxds. And every time it analyzes a mxd file I`m asked the connection dialogue and have to enter the connection details. Is there a way to open a database connection that is valid for all mxd?

Thanks,

Trashken

share|improve this question
4  
Just a guess - try the Create ArcSDE Connection file tool: resources.arcgis.com/en/help/main/10.1/index.html#//… I do know when you run the tool it validates by making a connection to SDE. So, I'm thinking by using this it might persist the open connection in your script, thus allowing you to analyze. –  KHibma Feb 25 '13 at 21:22
    
Thanks I`ll try it! –  Trashken Feb 26 '13 at 6:38
    
Didn`t work for me –  Trashken Feb 28 '13 at 9:57

1 Answer 1

I'm going to stand by my answer I posted as a comment. In the following script:

import arcpy

myMap = arcpy.mapping.MapDocument(r'c:\temp\sde.mxd')
analysis = arcpy.mapping.AnalyzeForMSD(myMap)
print analysis

I get this:

{'errors': {(u"Layer's data source is inaccessible", 3): [, ]}, 'messages': {}, 'warnings': {}}

(with the dialog box as you explain)

However, in this script which uses CreateDataBaseConnection (or use CreateArcSDE if you're using the SDE tier to connect through):

import arcpy

arcpy.CreateDatabaseConnection_management("c:/temp","kevin1","SQL_SERVER","ne2k864","DATABASE_AUTH","sde","sde","SAVE_USERNAME","kevin","#","TRANSACTIONAL","sde.DEFAULT","#")

myMap = arcpy.mapping.MapDocument(r'c:\temp\sde.mxd')
analysis = arcpy.mapping.AnalyzeForMSD(myMap)
print analysis

I get:

{'errors': {}, 'messages': {(u'Layer draws at all scale ranges', 30003): []}, 'warnings': {}}

If you have layers coming from multiple databases with multiple credentials you'll have to create a connection for each one of those. If this is a script you'll be running multiple times you'll either need to turn on overwriteOutput or delete the .SDE files prior to running again.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.