Hello,
I've writen a Python script which worked perfectly on v 10. now, when i have v 10.1, the script works good except for 1 part: df.zoomToSelectedFeatures. The script selects a parcel, copies it, adds it to an mxd, zooms to it (it's suppose to do it), changes its symbology, sets the df.scale and exports to JPEG file.
Here is the script:
This is only a trial example. the final one will have 'arcpy.GetParameterAsText(0)' for the Gush, Helka and workspace parameters.
I simply dont understand why the df.zoomToSelectedFeatures function doesnt work. i get a jpeg file with all the layers and the symbology, and the scale and the text changes, but without the zoom in to the selected features.
Will appriciate any help :-)
I've writen a Python script which worked perfectly on v 10. now, when i have v 10.1, the script works good except for 1 part: df.zoomToSelectedFeatures. The script selects a parcel, copies it, adds it to an mxd, zooms to it (it's suppose to do it), changes its symbology, sets the df.scale and exports to JPEG file.
Here is the script:
Code:
#Import the arcgisscripting module.
import arcpy
# Setting the Variabls.
# Input gush and Helka.
Gush = 11516
Helka = 23
# Output Location (the folder where the resualt will be saved).
Workspace = r"E:\Local Disk (E)\users\Ilan\Projects\Helkot_Maps\11516_23"
arcpy.env.workspace = Workspace
# Exporting the wanted Helka:
hel_openland_shp = r"W:\Av_data\CADASTER_2012-11-18\PARCEL_ALL.shp"
Output_Layer = "hel_openland_Layer"
arcpy.MakeFeatureLayer_management(hel_openland_shp, Output_Layer)
arcpy.SelectLayerByAttribute_management(Output_Layer, "NEW_SELECTION", " \"GUSH_NUM\" = " + str(Gush))
arcpy.SelectLayerByAttribute_management(Output_Layer, "SUBSET_SELECTION", "\"PARCEL\" = " + str(Helka))
result = arcpy.CopyFeatures_management(Output_Layer, "Gush_" + str(Gush) + "_Helka_" + str(Helka))
helkafc = result.getOutput(0)
# Setting the Map file and the Data Frames:
mxd = arcpy.mapping.MapDocument("E:\\Local Disk (E)\\users\\Ilan\\Projects\\Python\\Helkot_Maps_tool\\MXDproject.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Parcel_Map") [0]
# Adding the wanted Helka to the first Data Frame:
helka_layer = "Helka" + " " + str(Helka)
arcpy.MakeFeatureLayer_management(helkafc, helka_layer)
helkalyr = arcpy.mapping.Layer(helka_layer)
arcpy.mapping.AddLayer(df, helkalyr, "TOP")
# Setting the Scale for the Data Frame and applying symbology to the Helka:
arcpy.SelectLayerByAttribute_management(str(helkalyr), "NEW_SELECTION", "\"PARCEL\" = 23")
df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(str(helkalyr), "CLEAR_SELECTION", "")
inputLayer = arcpy.mapping.ListLayers(mxd, helkalyr.name, df)[0]
symbologyLayer = arcpy.mapping.Layer("E:\\Local Disk (E)\\users\\Ilan\\Projects\\Python\\Helkot_Maps_tool\\wanted_layer.lyr")
arcpy.mapping.UpdateLayer(df, inputLayer, symbologyLayer, True)
df.scale = 8000
# Changing text elements in the map to match the Gush and Helka:
for textElement in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if textElement.text == "map title":
textElement.text = "Gush" + " " + str(Gush) + " " + "Helka" + " " + str(Helka)
arcpy.RefreshActiveView()
# Exporting the Map file to a JPEG file:
arcpy.mapping.ExportToJPEG(mxd, Workspace, df_export_width=640, df_export_height=480, resolution=150,
world_file=False, color_mode=1, jpeg_quality=100, progressive=False)
I simply dont understand why the df.zoomToSelectedFeatures function doesnt work. i get a jpeg file with all the layers and the symbology, and the scale and the text changes, but without the zoom in to the selected features.
Will appriciate any help :-)