Wildcard in FIELD NAME (Model Builder)

4757
1
05-14-2014 02:02 AM
KathrinSchulte-Braucks
New Contributor III
Hello,

I've got the following issue to address:

I process a bunch of shapefiles with a certain name stored in a folder. I use the %name% variable to name the outputs of geoprocessing operations.

Now, I want to use an SQL statement for a Selection (Select Tool). I don't now the exact fieldname, because the field is produced during a geoprocessing task executed before (Identity). The name is something like "FID_" +[shapefilename]+ [s+further characters], but not exactly known. So I'd like to make a query such as: "FID"+%name% + "s*" > -1 . My thought is to pass a variable containing the expression needed for the Select Tool. So far it is possible to pass a string variable such as "FID_%name%" , but the s* Wildcard is not accepted as SQL syntax.

Any clues?

Tank you very much for your help!

Kathrin
0 Kudos
1 Reply
KathrinSchulte-Braucks
New Contributor III
Solution: Using the Calculate Value Tool with a Python statement.

Expression:
field()


Code Block:
def field():
  ColName = []
  CName = arcpy.ListFields("<pathtofolder>/%name%_id.shp", "FID_"+ "%name%"+ "_f*")
  ColName.insert(0, CName[0].name)
  return fieldName


Data Type:
Field

Then use the calculated Output Value as input for the next tool (e.g. Join Field)

When using a where clause for the Select tool e.g.:

Expression:

 field() 


Code Block:

def field():
  ColName = []
  CName = arcpy.ListFields("<pathtofolder>/%name%_id.shp", "FID_"+ "%name%"+ "_s*")
  ColName.insert(0, CName[0].name)
  where_clause = ColName[0] +' > -1'
  return where_clause



Data Type:


String

The output value can then be used as input for the Expression of the Select Tool.
0 Kudos