0

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 18, 2013 at 11:25
4
  • 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()". Commented May 18, 2013 at 11:33
  • Rather than use the JSFiddle links can you put your code into the body of your question, please? Commented May 18, 2013 at 11:53
  • @PolyGeo I am trying but it seems that few lines are going outside of the code section Commented 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. Commented May 18, 2013 at 22:53

1 Answer 1

2

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).

answered May 18, 2013 at 22:53
1
  • 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). Commented Apr 10, 2014 at 1:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.