|
POST
|
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.
... View more
08-29-2013
02:27 AM
|
0
|
0
|
2713
|
|
POST
|
This is what I see 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.
... View more
08-28-2013
02:36 PM
|
0
|
0
|
5000
|
|
POST
|
You can open ArcMap, and then navigate to C:\temp using the Catalog window. When you double-click on the script within the Toolbox, what do you see? Can you send a screen shot? What meter number did you specify?
... View more
08-28-2013
12:25 PM
|
0
|
0
|
5001
|
|
POST
|
Attached is a zip file with an example. Try the following: 1. Extract the zip file to your C:\Temp directory 2. Open ArcMap 3. Under C:\Temp, expand the Data.gdb > Graph toolbox > double-click on the Script 4. Specify a meter number, i.e. 8151830 5. Click OK to execute the tool Within your C:\Temp directory you should have a graph as a PDF. Is this what you are looking for?
... View more
08-28-2013
11:26 AM
|
0
|
0
|
5001
|
|
POST
|
The problem is that the field is a String. The empty value for the ARCLENGTH field contains a space. The below code should work: mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
dsc = arcpy.Describe(lyr)
sel_set = dsc.fidSet
if dsc.shapeType == "Polyline":
rows = arcpy.SearchCursor(lyr, "OBJECTID = " + sel_set)
for row in rows:
arcLength = row.ARCLENGTH
shapeLength = row.shape.length
if len(arcLength) > 1:
print arcLength
else:
print shapeLength
del row, rows
... View more
08-28-2013
11:19 AM
|
0
|
0
|
1715
|
|
POST
|
That is what the original script that I posted does. What you will need to do is create a sample graph and update the script with the correct paths to your data. Then, create a toolbox > right-click on the toolbox > Add Script > browse to the script. You will also need to add a parameter to the script of type Long. A user can then click on the script and it will open a dialog for them to specify a Meter Number. Once they do and execute the tool, the meter number is queried and the graph is saved to a PDF.
... View more
08-28-2013
11:05 AM
|
0
|
0
|
4508
|
|
POST
|
Can you export a small portion of the feature class you are using, zip it, and upload it here?
... View more
08-28-2013
10:50 AM
|
0
|
0
|
1885
|
|
POST
|
Your fields need to be a list. http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000011000000 Instead of: fields = "BILLING_PERIOD";"METER_NUMBER";"KWH";"KW_DEMAND" try: fields = ["BILLING_PERIOD","METER_NUMBER","KWH","KW_DEMAND"] Mind me asking what's the purpose of creating a list of the meter numbers?
... View more
08-28-2013
10:45 AM
|
0
|
0
|
4508
|
|
POST
|
Attached is some data you can test with. Add the feature class to ArcMap, select a single line, then execute the following: mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
dsc = arcpy.Describe(lyr)
sel_set = dsc.fidSet
if dsc.shapeType == "Polyline":
rows = arcpy.SearchCursor(lyr, "OBJECTID = " + sel_set)
for row in rows:
arcLength = row.ARCLENGTH
shapeLength = row.shape.length
if arcLength > 0:
print arcLength
else:
print shapeLength
del row, rows
... View more
08-28-2013
10:38 AM
|
0
|
0
|
1885
|
|
POST
|
You can use the Table to Table conversion tool to create a .dbf file. Then you can use python's os.rename() method to rename the file to a .csv file. Ex: os.rename(r"C:\Temp\Gages.dbf", r"C:\Temp\Gages.csv")
... View more
08-28-2013
08:52 AM
|
0
|
0
|
1401
|
|
POST
|
Also, change arcpy.da.SearchCursor, to arcpy.SearchCursor.
... View more
08-28-2013
06:20 AM
|
0
|
0
|
2764
|
|
POST
|
Check the name of your OBJECTID field (right-click on layer > Properties > Fields tab). It may be OID, or OBJECTID1.
... View more
08-28-2013
06:15 AM
|
0
|
0
|
2764
|
|
POST
|
Take a look at the help links. The arcpy.da.SearchCursor is formatted differently. arcpy.SearchCursor http://resources.arcgis.com/en/help/main/10.2/index.html#//018v00000050000000 arcpy.da.SearchCursor http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000011000000 Can you post the exact code you're using in ArcMap?
... View more
08-28-2013
06:02 AM
|
0
|
0
|
2764
|
|
POST
|
Hi James, If this is a feature class, try the following below. If this is a shapefile, you will have to update the SearchCursor to use FID instead of OBJECTID. for lyr in arcpy.mapping.ListLayers(mxd):
tlyr = lyr
dsc = arcpy.Describe(tlyr)
sel_set = dsc.fidSet
if dsc.shapeType == "Polyline":
rows = arcpy.SearchCursor(tlyr, "OBJECTID = " + sel_set)
for row in rows:
arcLength = row.ARCLENGTH
shapeLength = row.shape.length
if arcLength > 0:
print arcLength
else:
print shapeLength
del row, rows
... View more
08-28-2013
05:17 AM
|
0
|
0
|
2764
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a month ago | |
| 4 | 05-07-2020 05:14 PM | |
| 1 | 03-25-2026 04:16 AM | |
| 1 | 03-16-2026 01:00 PM | |
| 1 | 12-22-2025 10:39 AM |
| Online Status |
Offline
|
| Date Last Visited |
14 hours ago
|