I am trying to develop a Geoprocessing tool that creates a report from my parcel service in a Web AppBuilder, using the Geoprocessing widget.
I have included my code below, it is not complete yet as I am planning to create a PDF. I am currently outputting a text file with all the data I want to include.
I am trying to be able to select a parcel polygon in the Web AppBuilder, then output that data to a report. When I test the script in ArcGIS Pro it works! When I select the same parcel in Web AppBuilder a URL is returned linking to the text file, however no parcel data is in the text file (As seen below).
Code:
import arcpy
import os
import sys
def ParcelData(parcels):
arcpy.AddMessage("ParcelData...")
fields = []
try:
desc = arcpy.Describe(parcels)
FIDSet = desc.FIDSet
record = [int(FID) for FID in FIDSet.split(";")] if FIDSet else []
record = record[0]
fields = arcpy.da.SearchCursor(parcels, "*", where_clause="OBJECTID=" + str(record))
except:
try:
pan = 403539
fields = arcpy.da.SearchCursor(parcels, "*", where_clause="PAN=" + str(pan))
except Exception as e:
arcpy.AddMessage(e)
return fields
def PDFGenerator(in_data, pdf_name):
fields = ParcelData(in_data)
arcpy.AddMessage(fields)
arcpy.AddMessage("PDFGenerator...")
try:
record = ()
file = os.path.join(arcpy.env.scratchFolder, pdf_name + ".txt")
text = open(file, 'w')
with fields as cursor:
for row in cursor:
record = row
arcpy.AddMessage(record)
text.write(str(record) + " TEST!!!")
text.close()
except Exception as e:
arcpy.AddMessage(e)
file = os.path.join(arcpy.env.scratchFolder, pdf_name + ".txt")
text = open(file, 'w')
text.write(str(e))
text.close()
arcpy.SetParameter(2, file)
return file
if __name__ == '__main__':
arcpy.AddMessage("Starting...")
arcpy.AddMessage("Parcels...")
try:
in_data = arcpy.management.MakeFeatureLayer(arcpy.GetParameter(0), 'parcels')
arcpy.AddMessage("- Feature Layer")
except:
in_data = arcpy.GetParameter(0)
arcpy.AddMessage("- Layer")
pdf_name = arcpy.GetParameterAsText(1)
arcpy.AddMessage("Output PDF...")
PDFGenerator(in_data, pdf_name)
ArcGIS Pro Results:
(468169, 'NORTH ADDITION', None, '01', 'Lot', None, 'tbd parcels doc 01S01W10_obj43861', None, None, None, 'Northeast City', 'Exempt ', 'Shoreway Drive Park', 'FAIRBANKS AK 99701 4615', '', 0.0, 2155.0, '800 CUSHMAN ST', 19.56, 'FAIRBANKS CITY OF', '', '', 'FAIRBANKS, CITY OF', 2021, 2155.0, 24261, 42826.871352714435, 863.0507574903871, '{A5D60ADF-F7B1-4B38-8FDC-B2DB9A8DD764}', (1372593.2270107588, 3966946.471093751)) TEST!!!
Web AppBuilder Results:
() TEST!!!