I have a Script Tool set up and its Python code executes properly when I run it outside of ArcGIS Pro.
But when I execute the script tool that the same code is connected to in ArcGIS Pro, it fails in this way:
First condo ARN value is 410822000220226
Exception encountered
ERROR 000358: Invalid expression Failed to execute (MakeFeatureLayer).
The code leading up to this point is:
def condo_script_tool(cntNewCondos, txtARN, subType, ws):
arcpy.AddMessage("First condo ARN value is " + txtARN)
arcpy.env.overwriteOutput = True
env.workspace = ws
proc_FC = arcpy.CreateFeatureclass_management("in_memory", "condo_proc", "POLYGON", "bc_dev.GIS_ADMIN.parcels")
target_FC = "parcels"
# Put in error trapping in case an error occurs when running tool
try:
# Make a layer from the feature class with only the parcel that has the desired ARN
arcpy.MakeFeatureLayer_management(target_FC, "condos_lyr"," \"ROLLNUM15\" = \'" + txtARN + "\' AND SUBTYPE = "+ str(subType))
...
Now I ask help please on why this code succeeds outside of Pro but fails inside of it. Could the target_FC maybe be the cause of the problem? How can I make it not be?
Thanks,
Justin
I think maybe you are missing single quotes around the last part of the SQL expression for subType. Is it a string or a number value? Try using f-string to build the expression.
Thank you @BlakeTerhune for the suggestion, however it did not change anything.
The Subtype field is a number value. Whether I include the single quotes or not makes no difference.
I expect it's more correct to leave them out given it's not a string data type and "where" clauses later in the script using that field succeed with no single quotes around it.
What other details might I provide, please, to help find a solution?