#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)
Solved! Go to Solution.
# Import the arcgisscripting module. import arcpy # Setting the Variabls. # Input gush and Helka. Gush = arcpy.GetParameterAsText(0) Helka = arcpy.GetParameterAsText(1) # Output Location (the folder where the resualt will be saved). Workspace = arcpy.GetParameterAsText(2) 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) arcpy.SelectLayerByAttribute_management(Output_Layer, "CLEAR_SELECTION", "") # Setting the Map file and the Data Frames: mxd = arcpy.mapping.MapDocument(r"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" + "_" + 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: lyr = arcpy.mapping.ListLayers(mxd, helkalyr.name, df)[0] print lyr arcpy.MakeFeatureLayer_management(helkalyr, lyr) result1 = arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "") if int(arcpy.GetCount_management(lyr).getOutput(0)) > 0: print result1.getOutput(0) df.zoomToSelectedFeatures() df.scale = 8000 arcpy.SelectLayerByAttribute_management(lyr, "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) # 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" + " " + Gush + " " + "Helka" + " " + 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)
df.scale = 8000
df.extent = lyr.getSelectedExtent()
You have this set to a static scale. Is this not the result you are getting?
df.scale = 8000
You could also try isolating the layer to make sure there aren't any other selections.
df.extent = lyr.getSelectedExtent()
That error seems to indicate you are not selecting anything or your selection is not valid. Have you checked to see if you actually select anything using .getOuput() or .FIDSet? Have you tried doing this process manually in ArcMap?
Thank you for your help. i have added a line to the script to check if there is actually something being selected usint getOutput (), and then printing the result. I do get the name of the parcel, which means that it is being seleted. But still, df.zoomToSelectedFeatures is not working. The jpeg is still fixed on another part of the map and not on the selected parcel.
can the be some other way of writing this is V 10.1? since its working in v 10? I cant think on anything else, but im not that expirienced in Python.
# Import the arcgisscripting module. import arcpy # Setting the Variabls. # Input gush and Helka. Gush = arcpy.GetParameterAsText(0) Helka = arcpy.GetParameterAsText(1) # Output Location (the folder where the resualt will be saved). Workspace = arcpy.GetParameterAsText(2) 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\" = " + Gush) arcpy.SelectLayerByAttribute_management(Output_Layer, "SUBSET_SELECTION", "\"PARCEL\" = " + Helka) result = arcpy.CopyFeatures_management(Output_Layer, "Gush_" + Gush + "_Helka_" + Helka) helkafc = result.getOutput(0) # Setting the Map file and the Data Frames: mxd = arcpy.mapping.MapDocument(r"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" + " " + Helka arcpy.MakeFeatureLayer_management(helkafc, helka_layer) helkalyr = arcpy.mapping.Layer(helka_layer) arcpy.mapping.AddLayer(df, helkalyr, "TOP") # Setting the Scale for the first Data Frame and applying symbology to the Helka: result = arcpy.SelectLayerByAttribute_management(helkalyr, "NEW_SELECTION", "\"PARCEL\" = 23") if int(arcpy.GetCount_management(helkalyr).getOutput(0)) > 0: print result.getOutput(0) df.scale = 8000 arcpy.SelectLayerByAttribute_management(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) # 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" + " " + Gush + " " + "Helka" + " " + 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)
df.extent = helkalyr.getSelectedExtent()
# Import the arcgisscripting module. import arcpy # Setting the Variabls. # Input gush and Helka. Gush = arcpy.GetParameterAsText(0) Helka = arcpy.GetParameterAsText(1) # Output Location (the folder where the resualt will be saved). Workspace = arcpy.GetParameterAsText(2) 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) arcpy.SelectLayerByAttribute_management(Output_Layer, "CLEAR_SELECTION", "") # Setting the Map file and the Data Frames: mxd = arcpy.mapping.MapDocument(r"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" + "_" + 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: lyr = arcpy.mapping.ListLayers(mxd, helkalyr.name, df)[0] print lyr arcpy.MakeFeatureLayer_management(helkalyr, lyr) result1 = arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "") if int(arcpy.GetCount_management(lyr).getOutput(0)) > 0: print result1.getOutput(0) df.zoomToSelectedFeatures() df.scale = 8000 arcpy.SelectLayerByAttribute_management(lyr, "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) # 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" + " " + Gush + " " + "Helka" + " " + 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)