Ask A Cartographer

File Name with Calculate Field

September 21 2010 | 4 comments
Categories: Map Data


I'm trying to create a model that would add a field to a feature class and then add it's name to that field (because they are later merged and I need to know which file they're from)

In the calculate field tool in my model, I have to specify (with Python if possible), what my FileName variable value is, but I don't know how. Right now, it add all the path, but I just want the name...

What should I write in the Code Box?


Mapping Center Answer:

To calculate the field with the feature class name, you need to parse the feature class path. If you are using 9.3, you can download the 'Parse Feature Class Name Toolbox' from Mapping Center in the Models & Script gallery under ArcGIS Resources and use it in your model. Use the output from this tool as an inline variable (this is called "Output" in our model, so for our model, the syntax would be %Output% - note that the name is case sensitive) in the Expression part of the of Calculate Field dialog.

There is one change you will have to make to the model because your input will be a feature class not a .dbf file. So after you add the toolbox to ArcToolbox, expand the view for the ParceFCName toolbox, right click the ParceFCName script and click Properties. On the Parameters tab, click dBase Table in the Data Type column and select Feature Class to change the Input Type to Feature Class, which you need for your model. Then click OK to keep the changes.

If you are using ArcGIS 10, Parse Path is available as a model-specific tool. You can also use Iterators inside the model to loop through each of the feature classes.

Cartographer / GIS Specialist posted by Francois Turcotte-Goulet on Sep 22 2010 11:16AM
Thanks! I'll try that right away!
Let us know! posted by Aileen Buckley on Sep 22 2010 11:20AM
Hopefully this will work for you! Let us know if you need more help!
Type mismatch error posted by Dan Seidensticker on Aug 24 2011 7:21AM
I'm using the Parse Feature Class Name for the same purpose - to calculate the name of a feature class (EI_1_Buffer)into a field. However, it looks like I'm getting a type mismatch error. The Output from Parse Feature Class Name is a String ((EI_1_Buffer) and the field I want to calculate the String into is Text. Any thoughts on why I get this error?

ERROR 000539: Runtime error : name 'EI_1_Buffer' is not defined
Item not found in this collection.
Failed to execute (Calculate Field).
re:Type mismatch error posted by Rajinder Nagi on Aug 24 2011 2:11PM
Make sure you use double quotes (e.g. "%Output%") for the inline variable in the expression in the Calculate Field tool. This should solve the issue.

If you would like to post a comment, please login.

Contact Us | Legal | Privacy |