Python scripting error from Map Automation module

524
5
06-15-2022 03:28 PM
Labels (1)
SarahBlake
New Contributor III

Hi.  I'm a GIS Instructor at a community college, trying to incorporate more Python into my curriculum.  I've assigned my students the ESRI course, "Python Scripting for Map Automation" for desktop, but one student is having repeated error messages in the second course exercise - see snip below: 

I'm wondering if there is an issue related to where the Python program 'lives' on the student's computer, and that's why changing the workspace gives errors? Thanks if anyone has ideas on what I can advise the student to try.

Sarah

SarahBlake_0-1655331620694.png

 

0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor

missing a \

path = r"c:\folder\sub"

path + r"\some.gdb"  # -- add \
'c:\\folder\\sub\\some.gdb'

... sort of retired...
0 Kudos
2Quiker
Occasional Contributor II

Try remove the "r" from r"\city of westervill.mdb" and r"\westerville.gdb". Are both the mdb and gdb in the same folder "c:\esritraining\mapscripting? Include arcpy.env.workspace

 

I have always done something like this.

 

mxd = arcpy.mapping.MapDocument("CURRENT")#mxd = arcpy.mapping.MapDocument(mxd)

mxd.findAndReplaceWorkspacePaths(r"Database Connections\Connection to OLD_sqlexpress.sde", r"Database Connections\Connection to New_sqlexpress.sde") #Database Servers\***.gds

for lyr in arcpy.mapping.ListLayers(mxd): 
    if lyr.name == "CITY_LIMITS":
        lyr.replaceDataSource(r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.7\ArcCatalog\***.gds", "SDE_WORKSPACE", "***.DBO.City_Limits","")
print "Successfully updated CITY_lIMITS data sources"

 

https://desktop.arcgis.com/en/arcmap/10.6/analyze/arcpy-mapping/updatingandfixingdatasources.htm

 

 

0 Kudos
SarahBlake
New Contributor III

Thanks for the ideas, Dan and 2Quiker.  I should've posted a snip of my version, what it should look like:

SarahBlake_0-1655335086141.png

I had my student add the 'r' thinking that would help with the path, but it didn't work either way.

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

the student was missing a "\" not just the r thing


... sort of retired...
0 Kudos
SarahBlake
New Contributor III

Hi.  So, yes the .gdb and the .mdb in this ESRI training module both exist in "C:\EsriTraining\MapScripting" folder...The "r" and extra "\" were not needed per the training module directions (I only has student add that later in effort to get code to work) - if look at my (not student) script in snip above, the code is the way the instructions were written in module (but didn't work for student).  The student copied/pasted the code from the Esri training directions originally, so I still wonder if the error codes have something to do with a different version of Python being referred to....this student (like I do too) has more than one version of Python installed, since Pro uses different version than ArcMap.  So maybe the question is how to make sure ArcMap is pulling from the correct one? Thanks.

0 Kudos