import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd,"Imagery")[0] lyr = arcpy.mapping.ListLayers(mxd, "High_resolution", df)[0] # Use the SelectLayerByAttribute tool to select and # zoom to the selection arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "AreaID = '%output_value%'") df.zoomToSelectedFeatures() arcpy.RefreshActiveView() # Export the map to a .jpg # Next Line Wrong! Outputs a jpeg actually called "test%output_value%.jpg" # outfile = "C:/Test/test" + "%output_value%" + ".jpg" # Next Line Wrong! Gives Syntax error # outfile = "C:/Test/test" + %output_value% + ".jpg" # Works.... outfile = "C:/Test/test1.jpg" arcpy.mapping.ExportToJPEG(mxd, outfile, df, df_export_width=1600, df_export_height=1200, world_file=True) # Clear the selection and refresh the active view arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION") arcpy.RefreshActiveView()
Solved! Go to Solution.
import sys, string, os, arcgisscripting gp = arcgisscripting.create(9.3) tablePath = gp.GetParameterAsText(0)
import arcpy import sys, string, os, arcgisscripting gp = arcgisscripting.create(9.3) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd,"Imagery")[0] lyr = arcpy.mapping.ListLayers(mxd, "High_resolution", df)[0] # Trying to get %output_value% as an in-script variable scriptVar = gp.GetParameterAsText(0) # Use the SelectLayerByAttribute tool to select and # zoom to the selection arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "Area = '%output_value%'") df.zoomToSelectedFeatures() arcpy.RefreshActiveView() outfile = "test" + scriptVar + ".jpg" arcpy.mapping.ExportToJPEG(mxd, r"C:\Test\\" + outfile, df, df_export_width=1600, df_export_height=1200, world_file=True) # Clear the selection and refresh the active view arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION") arcpy.RefreshActiveView()
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd,"Imagery")[0] lyr = arcpy.mapping.ListLayers(mxd, "High_resolution", df)[0] #Create a variable to hold the value you want to update in your table - can be set as a raw_input variable if you want to have #the user input this at the beginning of the model run #or you can hard code it in the script value = 'XXX' #create an update cursor rows = arcpy.UpdateCursor(lyr,'','','calcField;FeatID') #step through each row of the cursor, and perform all the actions you want while pointed at that row for row in rows: row.calcField = value #changes the value of the calcField attribute but doesn't make it permanent rows.updateRows(row) #updates the row so the change is permanent arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", '\"AreaID\" =' + row.FeatID) df.zoomToSelectedFeatures() arcpy.RefreshActiveView() outfile = "C:/Test/test1.jpg" arcpy.mapping.ExportToJPEG(mxd, outfile, df, df_export_width=1600, df_export_height=1200, world_file=True) arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION") arcpy.RefreshActiveView()
InScriptVar = arcpy.GetParameterAsText(0)
import sys, string, os, arcgisscripting gp = arcgisscripting.create(9.3) tablePath = gp.GetParameterAsText(0)
import arcpy import sys, string, os, arcgisscripting gp = arcgisscripting.create(9.3) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd,"Imagery")[0] lyr = arcpy.mapping.ListLayers(mxd, "High_resolution", df)[0] # Trying to get %output_value% as an in-script variable scriptVar = gp.GetParameterAsText(0) # Use the SelectLayerByAttribute tool to select and # zoom to the selection arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "Area = '%output_value%'") df.zoomToSelectedFeatures() arcpy.RefreshActiveView() outfile = "test" + scriptVar + ".jpg" arcpy.mapping.ExportToJPEG(mxd, r"C:\Test\\" + outfile, df, df_export_width=1600, df_export_height=1200, world_file=True) # Clear the selection and refresh the active view arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION") arcpy.RefreshActiveView()