File Name with Calculate Field
September 21 2010 |
4 comments
Categories:
Map Data
Hi!
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?
Thanks!!
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.
ERROR 000539: Runtime error
Item not found in this collection.
Failed to execute (Calculate Field).
If you would like to post a comment, please login.