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 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. So any help regarding will be great !! thanks in advance

share|improve this question
    
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 May 18 '13 at 11:33
    
Rather than use the JSFiddle links can you put your code into the body of your question, please? –  PolyGeo May 18 '13 at 11:53
    
@PolyGeo I am trying but it seems that few lines are going outside of the code section –  Sunil May 18 '13 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 May 18 '13 at 22:53

1 Answer 1

up vote 2 down vote accepted

Try this code and then re-open your MXD in ArcMap and I think you should see your new symology.

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

share|improve this answer
    
Its working thanks you : ) –  Sunil May 19 '13 at 5:08
    
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 Apr 10 at 1:11

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.