POST
|
Thank you! This helped me understand what I needed to do. So I got the loop to generate reports working, but I get a System.OutOfMemoryException: Out of Memory error for some of the reports I am trying to run. My layer does have a lot of photos in it, but I thought splitting it up with this loop would help out more. I got about half my reports to run, so not bad. But does anyone know how to fix this memory issue? #import the libraries you need
import arcpy
from arcpy import da
import os
#you tell it which layer you want to search through and which field(s) you want
fields=["OBJECTID", "Name"] #field list since I wanted more than one
tanks=da.SearchCursor("Storage", fields) #cursor
#using the cursor you established, you can loop through and do stuff
with tanks as cursor:
for item in cursor:
try:
#identify the map document
mxd = arcpy.mapping.MapDocument(r'MYPATH.mxd')
df = arcpy.mapping.ListDataFrames(mxd)[0]
#which layer you need to loop over
lyr = arcpy.mapping.ListLayers(mxd, "Storage", df)[0]
#create the pdf filename by using the Name field in Storage
filename="\\"+str(item[1])+".pdf"
#create the path for the pdf to be saved in
path=r'OUTFOLDERPATH' + filename
#this is where we search through the table to make our selections to run the report on
#I get the first value (the OBJECTID) from the cursor list
value=item[0]
#I identify that I will be searching using OBJECTID
field="OBJECTID"
#create an expression to use to select the record I want in this iteration
#it checks that "OBJECTID" is = whatever value we are on in the cursor list
exp=str(field) + "=" +str(value)
#now I make my selection from the lyr object, it uses the expression from above
point_lyr=arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",exp)
#now I can run the report on the lyr, specify the report template, give it the output path, and tell it to run on the selected items only
arcpy.mapping.ExportReport(lyr, r'REPORTPATH.rlf', path, "SELECTED")
except: #i do this because i get storage errors
continue Error from report viewer: Error from Python: Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\mapping.py", line 532, in ExportReport
return report_source._arc_object.ExportReport(*gp_fixargs((report_layout_file, output_file, dataset_option, report_title, starting_page_number, page_range, report_definition_query, extent, field_map), True))
RuntimeError: Error in generating report
... View more
03-18-2020
10:17 AM
|
0
|
1
|
1335
|
POST
|
I created a report in ArcMap that I would like to use to export reports for my data as PDFs, the problem is that when I run the report for all my data, there is not enough memory to handle it. One way to fix it is to select each row one by one and run the report on only the selected features. This would take a long time thought as I have over a hundred reports that would be generated. I am wondering if it is possible to run a python script to loop through my main data table, select the record, and then run my report on that selected feature, export that report to a PDF and then continue iterating through the other features in the same way. This is what I have so far, but I am not sure how to call the report to run in my script. Any ideas? import arcpy from arcpy import da import os #input the tank layer inTable = arcpy.GetParameterAsText(0) #specify output location for reports fileLocation = arcpy.GetParameterAsText(1) #tanks is my main data layer tanks=da.SearchCursor(inTable) #loop through layer for item in tanks: #select feature #run report #export report to fileLocation
... View more
03-12-2020
10:05 AM
|
0
|
3
|
1413
|
POST
|
Hi all, I made a mistake and deleted the direction field that was produced using the Geotagged Photos to Points geoprocessing tool. Is there a way to create a new field called "direction" and use the photo information to populate it? I don't want to run the Geotagged Photos to Points tool again because it would take a lot of work to get my layer back to where it is now. Thanks!
... View more
03-09-2020
08:16 AM
|
0
|
1
|
495
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|