Hello!
I am having a problem with the ExportReportToPdf tool. When i export a report from ArcGis Pro it includes the attachment and company logo (PNG). However when i export via Python its missing the company logo and throws the following error:
I tried using a TIFF instead of the PNG, but the same kind of error is thrown.
I access the report from the exported report file (rptx file). This file seems to be ok.
Does anybody know why it is not exporting the full report with the PNG?
It would help to share your code that you have. Click the ... and then click the </> icon to open a window where you can paste your code.
Thank you for your answer! I had to remove some things out of privacy considerations:
import arcpy
ZwolleOpdracht = xxx
ZwolleLekindicatie = xxx
Report = r"xxx.rptx"
output = xxx
arcpy.management.MakeFeatureLayer(ZwolleOpdracht, 'ZwolleOpdrachtTemp')
queryLekindicatie = """ {status} <> 'Verwerkt' """\
.format(status=(arcpy.AddFieldDelimiters(ZwolleLekindicatie, "Status")))
with arcpy.da.SearchCursor(ZwolleLekindicatie, ["OBJECTID", "Status"], queryLekindicatie) as cursor:
for x in cursor:
queryLekindicatieTemp = """ {objectid} = {objectid2} """ \
.format(objectid=(arcpy.AddFieldDelimiters(ZwolleLekindicatie, "OBJECTID")),
objectid2=x[0])
print(queryLekindicatieTemp)
arcpy.management.MakeFeatureLayer(ZwolleLekindicatie, 'ZwolleLekindicatieTemp{naam}'.format(naam=x[0]), queryLekindicatieTemp)
SelectieWnummer = arcpy.management.SelectLayerByLocation('ZwolleOpdrachtTemp', "WITHIN_a_DISTANCE",
"ZwolleLekindicatieTemp{naam}".format(naam=x[0]), 2, "NEW_SELECTION",
"NOT_INVERT")
with arcpy.da.SearchCursor(SelectieWnummer, ["OBJECTID", "Opdrachtnummer"]) as cursor2:
for y in cursor2:
wNummer = y[1]
print(y[1])
out_pdf = output + r"\{wnummer} Lekindicatie.pdf".format(wnummer=y[1])
arcpy.management.ExportReportToPDF(Report, out_pdf, queryLekindicatieTemp, 300, "BEST", "", "", "JPEG")
Nested cursors can cause a bad time. lines 28 and 29- are they on the right indent level? As is, they are outside of the cursor 2 scope and once the for y in cursor2 loop completes, y[1] shouldn't exist.
I'd recommend building a dictionary of objectid's from the first cursor, and then iterate over the dictionary to perform the select by location.
Is that second cursor just to get the wNummer? The expression in the ExportReportToPDF is using the OBJECTID of the first cursor, so its not picking up/using the OBJECTID of the second cursor, if that is your intention. Could need a new sql query using OBJECTIDS from the second featureclass? Maybe something like:
arcpy.management.MakeFeatureLayer(ZwolleOpdracht, 'ZwolleOpdrachtTemp')
queryLekindicatie = f"""{arcpy.AddFieldDelimiters(ZwolleLekindicatie, 'Status')} <> 'Verwerkt'"""
# create dictionary of objectids and other fields from first featureclass
feat_dict = {x[0]: {'OBJECTID': x[0], 'Status': x[1]} for x in arcpy.da.SearchCursor(ZwolleLekindicatie, ["OBJECTID", "Status"], queryLekindicatie)}
# iterate over the dictionary to select by location from other featureclass
for k, v in feat_dict.items():
queryLekindicatieTemp = f"""{arcpy.AddFieldDelimiters(ZwolleLekindicatie, 'OBJECTID')} = {v['OBJECTID']} """
print(f"OBJECTID: {k}\t status: {v['Status']}\t queryLekindicatieTemp: {queryLekindicatieTemp}")
arcpy.management.MakeFeatureLayer(ZwolleLekindicatie, f"ZwolleLekindicatieTemp{v['OBJECTID']}", queryLekindicatieTemp)
SelectieWnummer = arcpy.management.SelectLayerByLocation('ZwolleOpdrachtTemp', "WITHIN_A_DISTANCE", f"ZwolleLekindicatieTemp{v['OBJECTID']}", 2, "NEW_SELECTION")
with arcpy.da.SearchCursor(SelectieWnummer, ["OBJECTID", "Opdrachtnummer"]) as cursor2:
objectids = []
out_pdf = None
for y in cursor2:
wNummer = y[1]
print(y[1])
out_pdf = output + r"\{wnummer} Lekindicatie.pdf".format(wnummer=y[1])
objectids.append(y[0])
sql = f"""{'OBJECTID'} IN ({str(objectids)[1:-1]})"""
arcpy.management.ExportReportToPDF(Report, out_pdf, sql, 300, "BEST", "", "", "JPEG")