1

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

1

2 Answers 2

3

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

2

It looks like the Definition Query tool you have written using Python script takes a single input of type SQL Expression.

I think you will have more success if the only input to this tool is a String representing the Value i.e. hardwire the field and operator (at least for initial testing) or make them separate inputs (if you prefer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.