I am using ArcGIS for Desktop 10.1 and Server 10.1 on my machine Windows 7.
I am newbie in python & running simple python script for UniqueValuesSymbology it running fine if I use mxd as "current" but if I update with full mxd path then it’s not updating the layers symbology and did not show any error.
JSFiddle code 1 (using mxd path as current)
import arcpy
mxd = arcpy.mapping.MapDocument("current")
lyr = arcpy.mapping.ListLayers(mxd, "Population")[0]
if lyr.symbologyType == "UNIQUE_VALUES":
lyr.symbology.valueField = "SUB_REGION"
lyr.symbology.addAllValues()
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
del mxd
JSFiddle code 2 (using complete mxd path )
import arcpy
mxd = arcpy.mapping.MapDocument("D:\\ArcGIS_Data\\data\\y1.mxd")
lyr = arcpy.mapping.ListLayers(mxd, "Population")[0]
if lyr.symbologyType == "UNIQUE_VALUES":
lyr.symbology.valueField = "SUB_REGION"
lyr.symbology.addAllValues()
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
del mxd
I researched on Google, web help and ArcPy syntax for mxd_path still not getting any clue & Python path is perfect in environmental variables
The reason of using mxd path is that I want to make this script automatic using windows scheduler.
-
What's the third line in your code 2? "print.mxd.filepath" looks like it would throw an error. Also, you seem to be lacking an "mxd.save()".PolyGeo– PolyGeo ♦2013年05月18日 11:33:50 +00:00Commented May 18, 2013 at 11:33
-
Rather than use the JSFiddle links can you put your code into the body of your question, please?PolyGeo– PolyGeo ♦2013年05月18日 11:53:18 +00:00Commented May 18, 2013 at 11:53
-
@PolyGeo I am trying but it seems that few lines are going outside of the code sectionSunil– Sunil2013年05月18日 12:01:07 +00:00Commented May 18, 2013 at 12:01
-
It worked fine for me as you can probably see from the edit I just made to your question with a simple copy/paste from your JSFiddle links.PolyGeo– PolyGeo ♦2013年05月18日 22:53:46 +00:00Commented May 18, 2013 at 22:53
1 Answer 1
Try this code and then re-open your MXD in ArcMap and I think you should see your new symbology.
import arcpy
mxd = arcpy.mapping.MapDocument("D:\\ArcGIS_Data\\data\\y1.mxd")
lyr = arcpy.mapping.ListLayers(mxd, "Population")[0]
if lyr.symbologyType == "UNIQUE_VALUES":
lyr.symbology.valueField = "SUB_REGION"
lyr.symbology.addAllValues()
mxd.save()
del mxd
As @Roland commented you were running your code as a process separate from your server, which was reading the map document off disk. Although your code modified the document, it hadn't saved the changes to the mxd file (which is what the server would show).
-
so the crux of the answer is that the OP was running his/her code as a process separate from their server, which was reading the map document off disk. Although his code modified the document, it hadn't saved the changes to the mxd file (which is what the server would show).Roland– Roland2014年04月10日 01:11:27 +00:00Commented Apr 10, 2014 at 1:11