Adding a field name and Parsing the filename in model builder

3342
7
05-14-2018 03:12 PM
VincentOgodo
New Contributor

I have created a new field name to hold the filename of each table am iterating. I have used the parse path to collect the filename but and preconditioned the the parsing so that the field can be added first before the filename is populated in the new created field. When I run the model I an error that workspace not set for geoprocessor. Any help please?

Vincent

0 Kudos
7 Replies
JoeBorgione
MVP Emeritus

Check this out :  000638: Workspace not set for GeoProcessor.—Help | ArcGIS Desktop 

And this: https://community.esri.com/thread/48342 

I can't quite get through your models logic, but make sure you are accessing a fgdb and not a feature class.  A workspace 'holds' the feature or table, so a workspace can be a directory (folder) that has a shapefile or dbf table.

That should just about do it....
VincentOgodo
New Contributor

I managed to overcome the problem and it works fine. The new problem I have now is how to select part(s) of the file names to be populated in to the new created field. As it is the whole file name is written but I just would like parts of the filename.

0 Kudos
DanPatterson_Retired
MVP Emeritus

What is an example of the filename that is being returned?

If it is a string, then there is not tool in arctoolbox to parse text, this can be done via a script or even a field calculator expression parsing the part you want.  For example to get the featureclass name from a full path in python you would use

fn = "C:/folder/file.gdb/featureclass"

fn.split("/")[-1]

'featureclass'

where fn would be your filename

0 Kudos
VincentOgodo
New Contributor

Thanks Dan,

Am actually dealing with Tables. The fieldname is a string e.g. et_2003-2004c12 where the last two digits are indicates month of december. 2003-2004 represents the years which I also want to extract out into a separate field. I am a dummy with scripting in python let alone programming strings.

0 Kudos
DanPatterson_Retired
MVP Emeritus

For your future reference... it is python 'slicing'

d = "et_2003-2004c12"
y = d[3:12]
m = d[-2:]
d, y, m('et_2003-2004c12', '2003-2004', '12')
curtvprice
MVP Esteemed Contributor

You really don't need the Parse Path step -- Name is already parsed, Name is the name of the table without any file extension. You can simply use Name in your Calculate Field expression -- that is: "%Name%".

VincentOgodo
New Contributor

This did not work. It created the field name but failed to populate the names. It resulted in empty records.

0 Kudos