Original User: willfishHello, I am a Python (v2.6.5) noob trying to plot a series of 3D polylines into graphs. So far I've come up with:
# Import system modules
import arcpy, os, sys, string
from arcpy import env
print "Modules imported."
# Set environment settings
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"X:\HaulRoad\SpatialData"
arcpy.env.scratchWorkspace = r"X:\HaulRoad\SpatialData"
print "Workspaces set."
# Set local variables
infc = "\HaulRd.gdb\Treatment\XS_2009BEBRklnTerr_interpZ_Rte_isect"
graph_template = r"\XS\XS_Seg02.55.grf" # template graph originally created with 3d Analyst profile tool, customized in Advanced Properties, then exported to grf format
print "Local variables set."
#create list of fields of interest from FC or table of interest
fields = ['SegID','STA_calc','shape.Z','shape.M']
#create empty list for cursor to populate
list = []
print "Table and empty list created."
# use search cursor to get field value for a given record
rows = arcpy.SearchCursor(infc, "", "", "SegID; STA_calc")
for row in rows:
list.append(row.SegID)
list.append(row.STA_calc)
del row, rows
print "Rows appended to temporary table. List deleted."
#remove duplicates from list
list = dict.fromkeys(list)
list = list.keys()
print "Duplicates removed."
#create a temporary memory variable
memoryFC = "in_memory" + "\\" + "virtualFC"
print "Memory Feature created."
for n in list:
arcpy.TableSelect_analysis(infc, memoryFC, "STA_calc = " + str(n))
out_Seg = fields[0]
out_STA = fields[1]
out_graph_name = n
out_graph_pdf = r"\XS\Script\XS_chart_Seg" + str(out_Seg) + str(out_STA) + ".pdf"
graph_data = memoryFC
# Create temporary feature layer
arcpy.MakeFeatureLayer_management(infc, "XS_lyr")
# Create the graph from temporary feature layer
graph = arcpy.Graph()
# Specify the title of the Graph
graph.graphPropsGeneral.title = "Segment " + out_Seg
# Specify the subtitle of the Graph
graph.graphPropsGeneral.subtitle = "Station " + out_STA
# Specify the title of the left axis
graph.graphAxis[0].title = "Elevation (ft)"
# Specify the title of the bottom axis
graph.graphAxis[2].title = "Station (ft)"
# Add a vertical bar series to the graph
graph.addSeriesLineVertical("XS_lyr", shape.Z, shape.M)
# Output a graph, which is created in-memory
arcpy.MakeGraph_management(graph_template, graph, out_graph_name)
# Save the graph as an PDF
arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 800, 600)
#clean in-memory
arcpy.Delete_management("in_memory")
print "PDFs created and memory cleaned."
I get an error in line 82 where I am adding the vertical line series. I assume the problem is that I am trying to plot values based on feature geometry as opposed to values in the attribute table.The source data is a polyline feature class with Z and M values in an Arc 10.0 SP4 file geodatabase. The features display properly in ArcScene based on their own elevation values and I'm able to locate other features along the lines (routes), so I'm pretty sure the Z and M geometry is solid. Is what I'm attempting possible without some intermediate conversion (e.g. converting vertices to points)? Thank-you,WillPS. I'm also trying to get chart titles and subtitles to dynamically update, but haven't gotten to testing that yet.