[GIS] Creating Definition Query tool in ModelBuilder that uses in-line variable

arcgis-desktopdefinition-querymodelbuilder

I'm having trouble using an in line variable derived from the Parse Path tool in ArcGIS ModelBuilder to create a definition query for a layer file.

I'm importing an xyz file to a feature class, and using Parse Path to obtain %Value%.
I would like to set a defintion query to something like the one shown below. I have a short Python script that was used to manually enter the def query, but would much rather use %Value% to derive it.

enter image description here

Best Answer

I made a test model based on the central branch of your model in the area surrounding the 'DefinitionQuery' script. Firstly, in your definition query model parameter, I believe for the SQL Expression you need double quotes surrounding the field name ("REF_SURVEY_ID" = '%Value%').

The other thing I am thinking is the logic/order of your tools. In my test I applied the 'DefinitionQuery' script on the Make XY Event Layer output and then applied symbology and finally, saved to a layer file for exporting or emailing as attachment.

To do this I added an output to my DefinitionQuery script so that I could set a precondition on the 'Apply Symbology From Layer' tool. This way I made sure that the DefinitionQuery was applied to my XY Event layer before further processing (you cannot set a tool as a precondition for something if it does not have an output). This idea comes from this esri forum post I found: Preconditions for Python scripts.

I added a boolean output parameter to my DefinitionQuery script and I set this value it in the python code (arcpy.SetParameter(2, 1)).

DefinitionQuery Model

DefinitionQuery Script Properties

Related Question