So I have a model builder code which works fine as intended.
The only thing I want to add to it is an if statement at the beginning of the code in line 24. That if true then don't run the rest of the script and just print script ran successfully. But if it's false then run the rest of the code as is.
Condition:
If in Grants_xlsx X is not NULL then run skip the rest of the code and run the last print statement.
Code:
# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2024-02-21 14:43:11
"""
import arcpy
import pandas as pd
def Model(): # Model
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True
arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Conversion Tools.tbx")
arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Data Management Tools.tbx")
DimTriCountyCities = "O:\\bla\\Ed\\GeocodeProject\\ModelGeodatabase.gdb\\DimTriCountyCities"
Grants_xlsx = r"\\path\Grants.xlsx"
BrowardCompositeLocator = "https://bla/Locator"
DimTriCountyCities_2_ = "O:\\path\\ModelGeodatabase.gdb\\DimTriCountyCities"
DimTriCountyCities_4_ = "O:\\path\\ModelGeodatabase.gdb\\DimTriCountyCities"
# Process: Excel To Table (Excel To Table) (conversion)
Grants_ExcelToTable = "O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable"
arcpy.conversion.ExcelToTable(Input_Excel_File=Grants_xlsx, Output_Table=Grants_ExcelToTable, Sheet="Grants")
# Process: Export Table (Export Table) (conversion)
Grants_Filtered = "O:\\path\\ModelGeodatabase.gdb\\Grants_Filtered"
arcpy.conversion.ExportTable(in_table=Grants_ExcelToTable, out_table=Grants_Filtered, where_clause="X IS NULL And Street_Address <> ''", field_mapping="Grant_Type \"Grant Type\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Grant_Type,0,255;Grant_Sub_Category \"Grant Sub-Category\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Grant_Sub_Category,0,255;Program_Area \"Program Area\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Program_Area,0,255;Name \"Name\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Name,0,255;District \"District\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,District,0,255;Street_Address \"Street Address\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Street_Address,0,255;City \"City\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,City,0,255;Postal_Code \"Postal Code\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Postal_Code,0,255;Funded_Amount \"Funded Amount\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Funded_Amount,-1,-1;website \"website\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,website,0,255;Fiscal_Year \"Fiscal Year\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Fiscal_Year,-1,-1")
# Process: Geocode Addresses (Geocode Addresses) (geocoding)
Grants_Filtere_GeocodeAddres = "O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres"
arcpy.geocoding.GeocodeAddresses(in_table=Grants_Filtered, address_locator=BrowardCompositeLocator, in_address_fields="Address Street_Address VISIBLE NONE;Address2 <None> VISIBLE NONE;Address3 <None> VISIBLE NONE;Neighborhood <None> VISIBLE NONE;City City VISIBLE NONE;County <None> VISIBLE NONE;State <None> VISIBLE NONE;ZIP Postal_Code VISIBLE NONE;ZIP4 <None> VISIBLE NONE;Country <None> VISIBLE NONE", out_feature_class=Grants_Filtere_GeocodeAddres, output_fields="MINIMAL")
# Process: Export Table (2) (Export Table) (conversion)
Grants_Unmatched = "O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched"
arcpy.conversion.ExportTable(in_table=Grants_Filtere_GeocodeAddres, out_table=Grants_Unmatched, where_clause="Status = 'U'", field_mapping="Grant_Type \"Grant Type\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Grant_Type,0,255;Grant_Sub_Category \"Grant Sub-Category\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Grant_Sub_Category,0,255;Program_Area \"Program Area\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Program_Area,0,255;Name \"Name\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Name,0,255;District \"District\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,District,0,255;Street_Address \"Street Address\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Street_Address,0,255;City \"City\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,City,0,255;Postal_Code \"Postal Code\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Postal_Code,0,255;Funded_Amount \"Funded Amount\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Funded_Amount,-1,-1;website \"website\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,website,0,255;Fiscal_Year \"Fiscal Year\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Fiscal_Year,-1,-1;Status \"Status\" true true true 1 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Status,0,1;Score \"Score\" true true true 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Score,-1,-1")
# Process: Join Field (Join Field) (management)
Grants_Unmatched_2_ = arcpy.management.JoinField(in_data=Grants_Unmatched, in_field="City", join_table=DimTriCountyCities_2_, join_field="CITY", fields=["X", "Y"])[0]
# Process: Export Table (3) (Export Table) (conversion)
Grants_UN_Updated = "O:\\path\\ModelGeodatabase.gdb\\Grants_UN_Updated"
arcpy.conversion.ExportTable(in_table=Grants_Unmatched_2_, out_table=Grants_UN_Updated, field_mapping="Grant_Type \"Grant Type\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Grant_Type,0,255;Grant_Sub_Category \"Grant Sub-Category\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Grant_Sub_Category,0,255;Program_Area \"Program Area\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Program_Area,0,255;Name \"Name\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Name,0,255;District \"District\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,District,0,255;Street_Address \"Street Address\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Street_Address,0,255;City \"City\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,City,0,255;Postal_Code \"Postal Code\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Postal_Code,0,255;Funded_Amount \"Funded Amount\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Funded_Amount,-1,-1;website \"website\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,website,0,255;Fiscal_Year \"Fiscal Year\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Fiscal_Year,-1,-1;X \"X\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,X,-1,-1;Y \"Y\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Y,-1,-1;Status \"Status\" true true true 1 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Status,0,1;Score \"Score\" true true true 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Unmatched,Score,-1,-1")
# Process: XY Table To Point (XY Table To Point) (management)
Grants_UN_XY = "O:\\path\\ModelGeodatabase.gdb\\Grants_UN_XY"
arcpy.management.XYTableToPoint(in_table=Grants_UN_Updated, out_feature_class=Grants_UN_XY, x_field="X", y_field="Y", coordinate_system="GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119521E-09;0.001;0.001;IsHighPrecision")
# Process: Export Table (4) (Export Table) (conversion)
Grants_NoAddress = "O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress"
arcpy.conversion.ExportTable(in_table=Grants_ExcelToTable, out_table=Grants_NoAddress, where_clause="Street_Address = ''", field_mapping="Grant_Type \"Grant Type\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Grant_Type,0,255;Grant_Sub_Category \"Grant Sub-Category\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Grant_Sub_Category,0,255;Program_Area \"Program Area\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Program_Area,0,255;Name \"Name\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Name,0,255;District \"District\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,District,0,255;Street_Address \"Street Address\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Street_Address,0,255;City \"City\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,City,0,255;Postal_Code \"Postal Code\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Postal_Code,0,255;Funded_Amount \"Funded Amount\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Funded_Amount,-1,-1;website \"website\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,website,0,255;Fiscal_Year \"Fiscal Year\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Fiscal_Year,-1,-1;Status \"Status\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Status,0,255;Score \"Score\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Score,-1,-1")
# Process: Join Field (2) (Join Field) (management)
Grants_NoAddress_3_ = arcpy.management.JoinField(in_data=Grants_NoAddress, in_field="City", join_table=DimTriCountyCities_4_, join_field="CITY", fields=["X", "Y"])[0]
# Process: Export Table (5) (Export Table) (conversion)
Grants_NA_Updated = "O:\\path\\ModelGeodatabase.gdb\\Grants_NA_Updated"
arcpy.conversion.ExportTable(in_table=Grants_NoAddress_3_, out_table=Grants_NA_Updated, field_mapping="Grant_Type \"Grant Type\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Grant_Type,0,255;Grant_Sub_Category \"Grant Sub-Category\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Grant_Sub_Category,0,255;Program_Area \"Program Area\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Program_Area,0,255;Name \"Name\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Name,0,255;District \"District\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,District,0,255;Street_Address \"Street Address\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Street_Address,0,255;City \"City\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,City,0,255;Postal_Code \"Postal Code\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Postal_Code,0,255;Funded_Amount \"Funded Amount\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Funded_Amount,-1,-1;website \"website\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,website,0,255;Fiscal_Year \"Fiscal Year\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Fiscal_Year,-1,-1;X \"X\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,X,-1,-1;Y \"Y\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Y,-1,-1;Status \"Status\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Status,0,255;Score \"Score\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_NoAddress,Score,-1,-1")
# Process: XY Table To Point (2) (XY Table To Point) (management)
Grants_NAU_XY = "O:\\path\\ModelGeodatabase.gdb\\Grants_NAU_XY"
arcpy.management.XYTableToPoint(in_table=Grants_NA_Updated, out_feature_class=Grants_NAU_XY, x_field="X", y_field="Y", coordinate_system="GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119521E-09;0.001;0.001;IsHighPrecision")
# Process: Export Table (6) (Export Table) (conversion)
Grants_WithXY = "O:\\path\\ModelGeodatabase.gdb\\Grants_WithXY"
arcpy.conversion.ExportTable(in_table=Grants_ExcelToTable, out_table=Grants_WithXY, where_clause="X IS NOT NULL And Street_Address <> ''", field_mapping="Grant_Type \"Grant Type\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Grant_Type,0,255;Grant_Sub_Category \"Grant Sub-Category\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Grant_Sub_Category,0,255;Program_Area \"Program Area\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Program_Area,0,255;Name \"Name\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Name,0,255;District \"District\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,District,0,255;Street_Address \"Street Address\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Street_Address,0,255;City \"City\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,City,0,255;Postal_Code \"Postal Code\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Postal_Code,0,255;Funded_Amount \"Funded Amount\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Funded_Amount,-1,-1;website \"website\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,website,0,255;Fiscal_Year \"Fiscal Year\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Fiscal_Year,-1,-1;X \"X\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,X,-1,-1;Y \"Y\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Y,-1,-1;Status \"Status\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Status,0,255;Score \"Score\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_ExcelToTable,Score,-1,-1")
# Process: XY Table To Point (3) (XY Table To Point) (management)
Grants_WithXY_XY = "O:\\path\\ModelGeodatabase.gdb\\Grants_WithXY_XY"
arcpy.management.XYTableToPoint(in_table=Grants_WithXY, out_feature_class=Grants_WithXY_XY, x_field="X", y_field="Y", coordinate_system="GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119521E-09;0.001;0.001;IsHighPrecision")
# Process: Export Features (Export Features) (conversion)
Grants_Matched = "O:\\path\\ModelGeodatabase.gdb\\Grants_Matched"
arcpy.conversion.ExportFeatures(in_features=Grants_Filtere_GeocodeAddres, out_features=Grants_Matched, where_clause="Status = 'M' Or Status = 'T'", field_mapping="Status \"Status\" true true true 1 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Status,0,1;Score \"Score\" true true true 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Score,-1,-1;Grant_Type \"Grant Type\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Grant_Type,0,255;Grant_Sub_Category \"Grant Sub-Category\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Grant_Sub_Category,0,255;Program_Area \"Program Area\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Program_Area,0,255;Name \"Name\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Name,0,255;District \"District\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,District,0,255;Street_Address \"Street Address\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Street_Address,0,255;City \"City\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,City,0,255;Postal_Code \"Postal Code\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Postal_Code,0,255;Funded_Amount \"Funded Amount\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Funded_Amount,-1,-1;website \"website\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,website,0,255;Fiscal_Year \"Fiscal Year\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Filtere_GeocodeAddres,Fiscal_Year,-1,-1")
# Process: Calculate Geometry Attributes (Calculate Geometry Attributes) (management)
Grants_Matched_2_ = arcpy.management.CalculateGeometryAttributes(in_features=Grants_Matched, geometry_property=[["X", "POINT_X"], ["Y", "POINT_Y"]], coordinate_system="GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]")[0]
# Process: Export Features (3) (Export Features) (conversion)
Grants_Final = "O:\\path\\ModelGeodatabase.gdb\\Grants_Final"
arcpy.conversion.ExportFeatures(in_features=Grants_Matched_2_, out_features=Grants_Final, field_mapping="Grant_Type \"Grant Type\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Grant_Type,0,255;Grant_Sub_Category \"Grant Sub-Category\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Grant_Sub_Category,0,255;Program_Area \"Program Area\" true true false 255 Text 0 0,First,#,O:\\path\ModelGeodatabase.gdb\\Grants_Matched,Program_Area,0,255;Name \"Name\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Name,0,255;District \"District\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,District,0,255;Street_Address \"Street Address\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Street_Address,0,255;City \"City\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,City,0,255;Postal_Code \"Postal Code\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Postal_Code,0,255;Funded_Amount \"Funded Amount\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Funded_Amount,-1,-1;website \"website\" true true false 255 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,website,0,255;Fiscal_Year \"Fiscal Year\" true true false 4 Long 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Fiscal_Year,-1,-1;X \"X\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,X,-1,-1;Y \"Y\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Y,-1,-1;Status \"Status\" true true false 1 Text 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Status,0,1;Score \"Score\" true true false 8 Double 0 0,First,#,O:\\path\\ModelGeodatabase.gdb\\Grants_Matched,Score,-1,-1")
# Process: Append (Append) (management)
if Grants_Final and Grants_NAU_XY and Grants_UN_XY and Grants_WithXY_XY:
Updated_Target_Dataset = arcpy.management.Append(inputs=[Grants_UN_XY, Grants_NAU_XY, Grants_WithXY_XY], target=Grants_Final)[0]
# Process: Table To Excel (Table To Excel) (conversion)
Grants_xlsx_3_ = "\\path\Grants.xlsx"
if Grants_Final and Grants_NAU_XY and Grants_UN_XY and Grants_WithXY_XY:
arcpy.conversion.TableToExcel(Input_Table=[Updated_Target_Dataset], Output_Excel_File=Grants_xlsx_3_, Use_field_alias_as_column_header="ALIAS")
if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(scratchWorkspace="O:\\path\\ModelGeodatabase.gdb", workspace="O:\\path\\ModelGeodatabase.gdb"):
Model()
print("Script ran successfully")
Solved! Go to Solution.
To check for the whole row with 1 field
if not None in row:
If there are multiple fields
chk = [0 if None in r else 1 for r in row]
if sum(chk) < len(chk) :
.... there are None values
else:
The fields don't contain none
You don't indent 91 at all, that is how the script runs
You should always return something, so scope your code
with arcpy.EnvManager(scratchWorkspace="O:\\path\\ModelGeodatabase.gdb",
workspace="O:\\path\\ModelGeodatabase.gdb"):
return_value = Model()
if return_value is None:
print("dismal failure")
else:
print("model succeeded")
just put the return value in the appropriate location
Hi @DanPatterson I also found another way that I put in line 24, this didn't require any indentation either 🙂
flag = True
with arcpy.da.SearchCursor(Grants_ExcelToTable,"X") as cursor:
for row in cursor:
if None in row:
flag = False
if flag == True:
print("No Null values found")
return
else:
print("Null values found, so running the model to geocode")
if condition is met:
indent the code to run
to run the code
print("success")
else:
print("condition not met")
Hi @DanPatterson, happy Friday, thank you for the super quick response. A follow up question what would be regarding the following syntax in this case as shown below what would be opposite syntax for None? X is the column that I am trying to check
with arcpy.da.SearchCursor(Grants_ExcelToTable,"X") as cursor:
for row in cursor:
if !None in row: #Syntax error here
Also if you look at the code it's defining a model in line 8 so I will use two indents from line 25-89 and single indent for line 91 if statement right?
To check for the whole row with 1 field
if not None in row:
If there are multiple fields
chk = [0 if None in r else 1 for r in row]
if sum(chk) < len(chk) :
.... there are None values
else:
The fields don't contain none
You don't indent 91 at all, that is how the script runs
You should always return something, so scope your code
with arcpy.EnvManager(scratchWorkspace="O:\\path\\ModelGeodatabase.gdb",
workspace="O:\\path\\ModelGeodatabase.gdb"):
return_value = Model()
if return_value is None:
print("dismal failure")
else:
print("model succeeded")
just put the return value in the appropriate location
Hi @DanPatterson I also found another way that I put in line 24, this didn't require any indentation either 🙂
flag = True
with arcpy.da.SearchCursor(Grants_ExcelToTable,"X") as cursor:
for row in cursor:
if None in row:
flag = False
if flag == True:
print("No Null values found")
return
else:
print("Null values found, so running the model to geocode")