Select to view content in your preferred language

ERROR 000358: Invalid expression on MakeFeatureLayer in Script Tool but no error in its Python code

310
2
04-16-2024 06:09 AM
JustinKraemer
Emerging Contributor

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

 

 

0 Kudos
2 Replies
BlakeTerhune
MVP Regular Contributor

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.

f"ROLLNUM15 = '{txtARN}' and SUBTYPE = '{subType}'"
0 Kudos
JustinKraemer
Emerging Contributor

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?

0 Kudos