I am having an syntax error from Pyscripter here and not sure why but I have a shapefile at the top of the TOC list which is the first and should be number zero when writing a listlayers as a zero but I still get the error .
The error is :
Traceback (most recent call last):
File "C:\Student\python\GeoTIFF.py", line 16, in <module>
gridlayer = arcpy.mapping.ListLayers(mxd,'JERGRIDINDEX', df,)[0]
IndexError: list index out of range
Take a look here the sytanx:: gridlayer = arcpy.mapping.ListLayers(mxd,'JERGRIDINDEX', df,)[0]
Hi Robert,
Would you be able to post all of your code? This will help troubleshoot this faster.
Here you go:
mport arcpy.mapping, os
mxd = arcpy.mapping.MapDocument (r"E:\workspace\Test.mxd")
arcpy.env.workspace = r"E:/workspace/images/"
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.scale = 40000
gridlayer = arcpy.mapping.ListLayers(mxd,'JERGRIDINDEX', df,)[0]
arcpy.SelectLayerByAttribute_management(gridlayer, "NEW_SELECTION")
for row in arcpy.SearchCursor(gridlayer):
df.panToExtent(row.shape.extent)
arcpy.RefreshActiveView()
filename = "E:/workspace/images/" + \
str(row.getValue("PageNumber")).zfill(4) + ".tif"
arcpy.mapping.ExportToTIFF(mxd, filename, df, df_export_width= 65000, df_export_height=30000,geoTIFF_tags=True)
## arcpy.mapping.ExportToTIFF(mxd, filename, df, df_export_width= 1280, \
## df_export_height=440, geoTIFF_tags=True)
print arcpy.GetMessages()
Everything looks correct, unless you are mis-spelling the layer name. However, since you want the first layer, you will not have to specify a name. Try the following:
gridlayer = arcpy.mapping.ListLayers(mxd,'', df,)[0]
One thing I did just notice is the arcpy.env.workspace. Since you are specifying an 'r' before the path, you will want to change the forward slashes to backslashes. Ex:
arcpy.env.workspace = r"E:\workspace\images"
I did the same thing what you suggest. I can try and run it from Python window but Pyscripter should be able to recongize it. Can I run this script from Pyscripter rather than in python window ?
Yes, you should be able to run this in Pyscripter.
How can I sync this Pyscripter to Arcmap ?
I'm not quite sure what you mean. When the code is executed in Pyscripter, you will not see the map's extent updated. However, you should still have the TIFF file created.
I am thinking maybe it is not working.How can Pyscripter communicate with ArcMap if I write these codes ?
Check out the Execute and debug your tool section for help attaching pyscripter to ArcMap for debugging.