Modelbuilder: calculate field with text of feature name

4295
6
07-26-2017 09:55 AM
RandyMorris
New Contributor II

I have tried to use the tool found here:

ArcGIS Tool: Inserts file name into attribute table - Data.gov 

but it doesn't work for me.  I need to allocate the feature name as a text cell value, so that I can then calculate other fields using that cell value.

I am running 10.4.1

If anyone can give me some help I would greatly appreciate it.

0 Kudos
6 Replies
curtvprice
MVP Esteemed Contributor

That model tool looks pretty hard coded to add a file name text field to all the feature classes in a workspace.

Can you describe more fully what you are trying to do? Add a text field with the file name for one feature class?

0 Kudos
curtvprice
MVP Esteemed Contributor

I think I can answer your question, which I am assuming is how to do this in Model Builder.

The Parse Path tool can be used to get the name from the input, and you can use the Calculate Field tool to calculate that value using a Python expression like:

r"%Dataset name%"

where Dataset name is the name of your output from the Parse Path tool.

0 Kudos
RandyMorris
New Contributor II

Hi guys, thanks so much for the responses.

I haven't had any luck using the "Parse Path" tool, but what did work in the end for my purposes was the "Get Field Value" tool (a Modelbuilder -only tool).

This allowed me to refer back to the original dataset, which contained a date column, and "Calculate Field" on a field created in the new dataset using the "gotten" value.

Thanks again!

curtvprice
MVP Esteemed Contributor
I haven't had any luck using the "Parse Path" tool

What was the problem? I seem to get the dataset name fine when I specify the NAME parameter.

Executing (Parse Path): ParsePath C:\Users\cprice\Documents\ArcGIS\Default.gdb\footprints NAME
Start Time: Wed Jul 26 17:42:39 2017
Succeeded at Wed Jul 26 17:42:39 2017 (Elapsed Time: 0.00 seconds)
Executing (Calculate Value): CalculateValue r"footprints" # Variant
Start Time: Wed Jul 26 17:43:02 2017
Value = footprints
Succeeded at Wed Jul 26 17:43:02 2017 (Elapsed Time: 0.09 seconds)

0 Kudos
RandyMorris
New Contributor II

When I tried to use the Parse Path tool, it just constantly failed to use the NAME value to calculate the field; no clue why.

That's why I was hoping maybe one of you guys could enlighten the process, like maybe I was putting in a wrong value somewhere. 
0 Kudos
curtvprice
MVP Esteemed Contributor

The Parse Path tool should get a dataset path (ie full path) input -- so it isn't the correct tool for the job, because the iterator you are using (Iterate Feature) doesn't generate dataset paths, it generates a selected set on a layer. The Get Field Value tool pulls data out a field from the first row in the selected set.