Hi
I am new to modelbuilder and a noob in python.
I am trying to take a snippet of a py code from the ESRI blog particularly example 3 to use in my model.
My goal is to check if a "Polygons" fc exists in a gdb and if it does not return true to run a set of additional gp tools.
If you are stuck at "if" – Part 1 | ArcGIS Blog
Create variable
- Workspace - workspace variable
- location of gdb
- set as parameter for input as a tool
- FeatureClasstoCheck - feature class variable
- fc located in a feature dataset of the workspace
- set as input of based on parameter
- %workspace%\Placemarks\Polygons ??
Expression;
x("%FeatureClassToCheck%", "%Workspace%")
Code Block
def x(FeatureClassToCheck, Workspace):
import arcpy
arcpy.env.workspace = Workspace
if arcpy.Exists(FeatureClassToCheck):
return "true"
else:
return "false"
Data Type
Boolean
Now everytime I run this script, it returns a false value even though a actual Polygons fc exists. I've tried hardcoding the location of the gdb and feature class in the script but it still returns a false value.
Ive also tried to just copy the Polygons fc into the parent gdb and just running %workspace%\Polygons but still returns a false value.
I am working in a citrix environment so I am not sure if that could be an issue?
ie workspace location: \\abc.com\PROFILES\RemoteDesktop\chow\desktop\workspace\test.gdb
Any suggestions?
Thanks!
Here's a guess based on something different between the ArcGIS help code example and your code:
Instead of:
arcpy.env.workspace = Workspace
Use:
env.workspace = Workspace
Based on ESRI's sample code in:
Checking for the existence of data
http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001p000000
I'm not an expert on Python; but maybe that one syntax change may resolve the issue.
Chris Donohue, GISP