Select to view content in your preferred language

Basic ?: Script to apply color map not working, need help

1019
5
06-13-2011 07:29 AM
MarkEllis
Emerging Contributor
I lifted some script text out of the help documentation, but nothing happens when I run it in the python window.  It appears that the list of rasters returns empty, as the script starts and then finishes in less than one second. I'm new to python, so am not even sure where to begin troubleshooting.

(See script posted in third reply, below)
Tags (2)
0 Kudos
5 Replies
MarkEllis
Emerging Contributor
Going through the python window in ArcMap has only made this more confusing.

Going line by line, there are no errors until the 'for raster in rasterList' line -
F2 returns a parsing error "expected an indented block"

Edit script or clear and reload with an indent,
F2 returns a parsing error "unexpected indent"

Really? How does one fix this? The Help documentation is worthless for details like this, any guidance from a user would be appreciated.
0 Kudos
DarrenWiens2
MVP Alum
If you post the code inside
 tags (see above the text box when posting), we can see your indentation (which is important in Python, btw).
0 Kudos
MarkEllis
Emerging Contributor
Reposted script with code tags...
## Add color map to DRGs
##====================================
import arcpy
from arcpy import env

 # Set workspace
arcpy.env.workspace = "Y:\base_data\State\IL\100k_DRGs"

 # Get list of grids
rasterList = arcpy.ListRasters("*", "GRID")

   for raster in rasterList:
      ## Add Colormap
      try:
     
          ##Assign colormap using clr file
          arcpy.AddColormap_management(raster, "#", "ISA_DRG.clr")
          print raster

      except:
          print "Add Colormap example failed."
          print arcpy.GetMessages()
0 Kudos
DarrenWiens2
MVP Alum
The problem is that your "for" is indented. You only indent after the colon (ie. after the "for").
0 Kudos
MarkEllis
Emerging Contributor
Thanks for the tip!  I also noted in documentation that the workspace path should contain / instead of \, as the latter is a line continuation character in python.  The two changes together worked, it is now running.

Syntax is tricky for the beginner...
0 Kudos