Solved! Go to Solution.
Right-click on the Script in the toolbox, click the Source tab, and make sure this is set to the script:
[ATTACH=CONFIG]27069[/ATTACH]
Also, check to make sure the Parameter is set:
[ATTACH=CONFIG]27070[/ATTACH]
Then, when you double-click on the Script in the toolbox, you should be presented with the following:
[ATTACH=CONFIG]27071[/ATTACH]
The user can enter in a meter number, and then an output graph will be created like the one attached.
import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\data.gdb" table = "Meters" fields = ["METER_NUMBER"] list = [] with arcpy.da.SearchCursor(table, fields) as cursor: for row in cursor: list.append("{0}".format(row[0])) del cursor, row #remove duplicates from list list = dict.fromkeys(list) list = list.keys() for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + n) out_graph_name = n out_graph_pdf = r"C:\Temp" + "\\" + n + ".pdf" input_template = r"C:\Temp\KW Demand.grf" input_data = r"in_memory\table_sel" # Create the graph graph = arcpy.Graph() # Add a vertical bar series to the graph graph.addSeriesBarVertical(input_data, "KW_DEMAND") # Specify the title of the left axis graph.graphAxis[0].title = "KW Demand" # Specify the title of the bottom axis graph.graphAxis[2].title = "Meter Number" # Specify the title of the Graph graph.graphPropsGeneral.title = "KW Demand by Meter" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an image arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
Here is an update to the script that will perform this for each unique meter number:import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\data.gdb" table = "Meters" fields = ["METER_NUMBER"] list = [] with arcpy.da.SearchCursor(table, fields) as cursor: for row in cursor: list.append("{0}".format(row[0])) del cursor, row #remove duplicates from list list = dict.fromkeys(list) list = list.keys() for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + n) out_graph_name = n out_graph_pdf = r"C:\Temp" + "\\" + n + ".pdf" input_template = r"C:\Temp\KW Demand.grf" input_data = r"in_memory\table_sel" # Create the graph graph = arcpy.Graph() # Add a vertical bar series to the graph graph.addSeriesBarVertical(input_data, "KW_DEMAND") # Specify the title of the left axis graph.graphAxis[0].title = "KW Demand" # Specify the title of the bottom axis graph.graphAxis[2].title = "Meter Number" # Specify the title of the Graph graph.graphPropsGeneral.title = "KW Demand by Meter" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an image arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
If you want to run this from toolbox, right-click on the script within toolbox > Properties > Parameters tab and delete the parameter previously created.
Jake-
Thank you for that. Close.....
However - I am getting this error:
<type 'exceptions.AttributeError'>: 'module' object has no attrbute 'da'
Failed to execute
Jake, he's running 10.0. The da cursors didn't show up until 10.1. Also, I don't think 10.0 cursors will take a list for the fields, just a formatted string.
Okay - I am trying to run this script off of ArcMap 10.0... I am in the process of upgrading to 10.2.... What is the latest Python that I will need?
import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\data.gdb" table = "Meters" list = [] rows = arcpy.SearchCursor(table) for row in rows: list.append(row.METER_NUMBER) del row, rows #remove duplicates from list list = dict.fromkeys(list) list = list.keys() for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "METER_NUMBER = " + str(n)) out_graph_name = n out_graph_pdf = r"C:\Temp" + "\\" + str(n) + ".pdf" input_template = r"C:\Temp\KW Demand.grf" input_data = r"in_memory\table_sel" # Create the graph graph = arcpy.Graph() # Add a vertical bar series to the graph graph.addSeriesBarVertical(input_data, "KW_DEMAND") # Specify the title of the left axis graph.graphAxis[0].title = "KW Demand" # Specify the title of the bottom axis graph.graphAxis[2].title = "Meter Number" # Specify the title of the Graph graph.graphPropsGeneral.title = "KW Demand by Meter" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an PDF arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
import arcpy import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb" table = "SERVICE_METERS_DEMAND_F1FEEDER" list = [] rows = arcpy.SearchCursor(table) for row in rows: list.append(row.TWACs_NUMBER) del row, rows # Remove duplicates from list list = dict.fromkeys(list) list = list.keys() for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "TWACs_NUMBER = " + str(n)) out_graph_name = n out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\F-1 Feeder" + "\\" + str(n) + ".pdf" input_template = r"C:\MEWCo GIS System\Electric Graphs\GIS Graph Temps\ELECTRIC METER DEMAND - KWH USAGE.grf" input_data = r"in_memory\table_sel" # Create the Graph graph = arcpy.Graph() # Add a Vertical Bar series to the graph - KWH Usage graph.addSeriesBarVertical(input_data, "KWH_USAGE") # Specify the title of the Left Axis graph.graphAxis[0].title = "KWH_USAGE" # Specify the title of the Bottom Axis graph.graphAxis[2].title = "BILLING_PERIOD" # Specify the title of the Graph graph.graphPropsGeneral.title = "KWH Usage by Electric TWACs Number" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an .PDF arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
import arcpy import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb" table = "SERVICE_METERS_DEMAND_F1FEEDER" list = [] rows = arcpy.SearchCursor(table) for row in rows: list.append(row.TWACs_NUMBER) del row, rows # Remove duplicates from list list = dict.fromkeys(list) list = list.keys() for n in list: arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "TWACs_NUMBER = " + str(n)) out_graph_name = n out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\F-1 Feeder" + "\\" + str(n) + ".pdf" input_template = r"C:\MEWCo GIS System\Electric Graphs\GIS Graph Temps\ELECTRIC METER DEMAND - KWH USAGE.grf" input_data = r"in_memory\table_sel" # Create the Graph graph = arcpy.Graph() # Add a Vertical Bar series to the graph - KWH Usage graph.addSeriesBarVertical(input_data, "KWH_USAGE") # Specify the title of the Left Axis graph.graphAxis[0].title = "KWH_USAGE" # Specify the title of the Bottom Axis graph.graphAxis[2].title = "BILLING_PERIOD" # Specify the title of the Graph graph.graphPropsGeneral.title = "KWH Usage by Electric TWACs Number" # Output a graph, which is created in-memory arcpy.MakeGraph_management(input_template, graph, out_graph_name) # Save the graph as an .PDF arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)
number = float(123456) print number '123456.0' # where you use the str(number) use a slice to remove the .0 in the pdf name str(number[:-2] '123456'