More

Avoiding error 000539 from code block in Calculate Value tool?

Avoiding error 000539 from code block in Calculate Value tool?


I do not have a very good understanding of python and have attempted to write a code block so that my model will skip rasters that do not contain any information and continue the process with rasters that do contain information. This is pertinent part of the model:

My current issue is that I keep getting this error:

Executing (Calculate Value): CalculateValue getValue(%Check Raster%) "def getValue(CheckRaster):
 import arcpy
 if "Has Values": return True
 if "Has No Values": return False" Variant Start Time: Fri Oct 30 10:16:54 2015 ERROR 000539: SyntaxError: invalid syntax (, line 1) Failed to execute (Calculate Value).

This is what my calculate value tool currently looks like:

Any ideas to how I could change the code so that there are not any more syntax errors? (The complete model can be found here.)

EDIT: The below answers were helpful but they have not entirely circumvented the problem yet. The check raster tool that I am using seems to always give an output that "Has Values" even though the following error will occur during Raster To Polygon: ERROR 010151: No features found in C:Usersoll0230DocumentsArcGISSuitability_stuff3Scratchpolygon_03.shp. Possible empty feature class.

I believe this means their is a problem with the check raster tool I have. Perhaps this has become more complicated that it needs to be. Is there a possible code that could be written in the calculate value tool that would check [email protected] for the presence of features?


Your code is incorrect this is what you need to do:

Set your model up as such, the Calculate Value tool is a precondition to some other tool, I've used Clip as an example. Your variable Raster_03 must have the forward slash for the code to work.

In the calculate value tool it should be set up as such (note output data type is set to Boolean):

The code is placed here for convenience:

import arcpy def CheckRaster(r): result = arcpy.GetRasterProperties_management(r, "MINIMUM") n = int(result.getOutput(0)) if n > 1: return True else: return False

You want to reference the outputs of the Check Raster tool in your function definition, not the function name itself.

Also from the help:

In-line variable of type string should be enclosed within quotes ("%string variable%") in an expression. In-line variables of type numbers (double, long) do not require quotes (%double%).

Try an expression like this:

getValue ("%Has Values%", "%Has No Values%")

And your code block:

def getValue (has, doesnt): if has: return True if doesnt: return False

Watch the video: Section, Week 2