POST
|
Tracey, A couple of comments: - I don't see an mxd.save() in your code so how is it that you expect to see changes? - If you are running this from the Python window, use "CURRENT" instead of the path to the file on disk. - it would be much easier to read your code if you posted it withing tags. Its the # button. You want to preserve indents.
Jeff Hi Jeff Thanks alot for your help. That was my first post and I didn't know how to include code, so thanks for the heads up. My code works now, here is a copy. I had the save a copy in my code, what I showed here was just a snippet, the real one is longer. I don't know what was wrong but I will continue with this code and add the rest in gradually to determine where my error was. Thanks again! # Import system modules import arcpy, sys, os, traceback, datetime from arcpy.mapping import * # set the current workspace (in the case a folder) arcpy.env.workspace = "E:\MapProject\MapProject.gdb" # Define Variables datapath = "J:\MapProject\MapProject.gdb\\" mappath = "J:\\MapProject\\Maps" newmxd= mappath + os.sep + "outReportMap.mxd" try: # Get the map document. In this case a custom template set up for map production mxd = MapDocument(mappath + os.sep + "ReportMapsTemplate9.mxd") print "Getting Map Document properties..." # Report properties of the Map Document print "Map Document Title: " + str(mxd.title) print "Map Document Author: " + str(mxd.author) mxd.author = "Tracey A. King" print "Map Document Author is now: " + str(mxd.author) print mxd.filePath print mxd.pageSize # Get a list of data frames # [0] indicates the first data frame # The data frame names is "Map Frame" df = ListDataFrames(mxd, "Map Frame")[0] print "Getting Data Frame properties..." # Report properties of the data frame named "Map Frame" print 'Data Frame Name: ' + str(df.name) print "Map Frame Map Units: " + str(df.mapUnits) print "Map Frame Scale: " + str(df.scale) # Get a list of layers in the table of contents of the map document TOCLayers = ListLayers(mxd) print "Processing layout elements..." # Loop through the layers for TOCLayer in ListLayers(mxd): print 'Layer Name: ' + str(TOCLayer.name) print 'Longname: ' + str(TOCLayer.longName) # 3. Set initial layer visibility if TOCLayer.name=="SSLT_Boundary": TOCLayer.visible=True if TOCLayer.name=="SSLT_Easements": TOCLayer.visible=True if TOCLayer.name=="NatGeo_World_Map": TOCLayer.visible=True # 4. Save to a new map document # Check to see if map document already exists, if it does delete it if arcpy.Exists(newmxd): arcpy.Delete_management(newmxd) # Save the changes in a new map document mxd.saveACopy(newmxd) print "A copy of the map document has been saved" except: # http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000000q000000 tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n " + str(sys.exc_type) + ": " + str(sys.exc_value) + "\n" msgs = "ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n" arcpy.AddError(msgs) arcpy.AddError(pymsg) print msgs print pymsg arcpy.AddMessage(arcpy.GetMessages(1)) print arcpy.GetMessages(1)
... View more
11-30-2012
01:35 PM
|
0
|
0
|
263
|
POST
|
I am trying to make changes to a map document using a python stand alone script. My script runs and I can get information from the map document but it does not make any changes to the document. One example is just to turn the layers on and off. A snippet of part of the script is included. Any help would be appreciated as even my instructor has not been able to make it work. # Import system modules import arcpy, sys, os, traceback, datetime from arcpy.mapping import * # set the current workspace (in the case a folder) arcpy.env.workspace = "E:\MapProject\MapProject.gdb" # Define Variables datapath = "E:\MapProject\MapProject.gdb\\" mappath = "E:\\MapProject\\Maps" try: # Get the map document. In this case a custom template set up for map production mxd = MapDocument(mappath + os.sep + "ReportMapsTemplate9.mxd") print "Getting Map Document properties..." # Report properties of the Map Document print "Map Document Title: " + str(mxd.title) print "Map Document Author: " + str(mxd.author) mxd.author = "Tracey A. King" print "Map Document Author is now: " + str(mxd.author) print mxd.filePath print mxd.pageSize # Get a list of data frames # [0] indicates the first data frame # The data frame names is "Map Frame" df = ListDataFrames(mxd, "Map Frame")[0] print "Getting Data Frame properties..." # Report properties of the data frame named "Map Frame" print 'Data Frame Name: ' + str(df.name) print "Map Frame Map Units: " + str(df.mapUnits) print "Map Frame Scale: " + str(df.scale) # Get a list of layers in the table of contents of the map document TOCLayers = ListLayers(mxd) print "Processing layout elements..." # Loop through the layers for TOCLayer in ListLayers(mxd): print 'Layer Name: ' + str(TOCLayer.name) print 'Longname: ' + str(TOCLayer.longName) # 3. Set initial layer visibility if TOCLayer.name=="SSLT_Boundary": TOCLayer.visible=True if TOCLayer.name=="SSLT_Easements": TOCLayer.visible=True if TOCLayer.name=="NatGeo_World_Map": TOCLayer.visible=True
... View more
11-28-2012
10:56 AM
|
0
|
0
|
1029
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|