AnsweredAssumed Answered

ERROR 000539: SyntaxError: invalid syntax

Question asked by evtinker on Jan 16, 2018
Latest reply on Jan 17, 2018 by evtinker

I am running Desktop 10.2.2.  I have been using model builder for years, creating models and exporting them to Python to automate tasks.  Recently, after a number of process failures due to broken connections, I have been trying to upgrade them to validate connections and results before continuing to the next steps.  What I wanted to do was simply check that a feature class was not empty before attempting to process it.  For test purposes I made a very simple model to check the row count on a polygon feature class and if it were greater than 0 copy it to a new feature class.  If the count was 0 it should stop.  Really simple.  

 

As a model it worked perfectly, so I exported it to Python.  That produced this:

 

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# TestModel.py
# Created on: 2018-01-16 11:41:45.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Load required toolboxes
arcpy.ImportToolbox("Model Functions")


# Local variables:
TestData = "C:\\Testing\\TestGeodatabase.gdb\\TestData"
TestPolys = "C:\\Testing\\TestGeodatabase.gdb\\TestData\\TestPolys"

# Process: Get Count
arcpy.GetCount_management(TestPolys)

# Process: Calculate Value
arcpy.CalculateValue_management("%Row Count% > 0", "", "Boolean")

# Process: Stop
arcpy.Stop_mb("true", "FALSE")

# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(TestPolys, TestData, "TestPolys2", "", "SHAPE_Length \"SHAPE_Length\" false true true 8 Double 0 0 ,First,#,C:\\Testing\\TestGeodatabase.gdb\\TestData\\TestPolys,SHAPE_Length,-1,-1;SHAPE_Area \"SHAPE_Area\" false true true 8 Double 0 0 ,First,#,C:\\Testing\\TestGeodatabase.gdb\\TestData\\TestPolys,SHAPE_Area,-1,-1", "")

 

Of course, that failed due to the IOError "The toolbox file Model Functions was not found", so I deleted the portion 

# Load required toolboxes
arcpy.ImportToolbox("Model Functions")

 

Now it generates this error:

 

Traceback (most recent call last):
File "C:\GeoProcessing\SWProcessingPythonSQL2\Scripts\TestModel.py", line 20, in <module>
arcpy.CalculateValue_management("%Row Count% > 0", "", "Boolean")
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 3808, in CalculateValue
raise e
ExecuteError: ERROR 000539: SyntaxError: invalid syntax (<expression>, line 1)
Failed to execute (CalculateValue).

 

Why, why, why can't Model Builder export Python code that actually works?  What is the point of a WYSIWYG GUI that doesn't produce functional code?

 

So, something is wrong with the expression.  What exactly would that be since it works in Model Builder?  This should be easy.  All I want to do is validate that there is data to process before processing it.

Outcomes