Apologies that I have not posted an image of my model, I am away from my computer for a while but am trying to sort this out anyways.

I have a number of different animal GPS location points, and a bunch of different habitat characteristics. I have built a simple model that uses the Near tool to calculate the distance from each point, create a new field using Add Field, naming it after the habitat characteristic shapefile name (using Parse Path and inline variable substitution), and then populates that added field with the NEAR_DIST values. It then continues on for all of my habitat characteristics.

I built the model a while ago and have since changed the names of the habitat characteristics (and there are a bunch of them) and unfortunately in the renaming them they are all now above the 10 character limit for a field name. What I was wondering is if there was any way to truncate the habitat characteristic shapefile title to 10 characters so that the add field tool doesn't error out.

Thanks in advance, and if you need any more information please let me know. I tend to leave things out by mistake when I ask questions on here.

Edit - Examples of habitat names are - 2001 Upland, 2001 Harvest, 2001 Deciduous

Essentially I need to remove the year and the space and they will all be under 10 characters.

Also, at home now so here is the tool I created. It runs through but doesn't successfully "Add Field" because its trying to name it after the "Near Feature" (the habitats whose names are too long) and so it just skips it.

enter image description here

  • 1
    Can you provide some examples of the "habitat characteristic shapefile title[s]" that you are using? It is very easy to just chop anything past 10 characters but if they all start with the same 10 characters then that will be of no use. Also, are you using ArcGIS for Desktop 10.0 or 10.1? – PolyGeo May 20 '13 at 8:40
  • That makes sense @PolyGeo I've edited the question to include examples of the titles and a bit more description plus a screenshot of my tool. Thanks for the help. – HeidelbergSlide May 20 '13 at 16:53
  • Oh, and I'm running ArcGIS for Desktop 10.0 – HeidelbergSlide May 20 '13 at 17:51
  • Are you trying to edit field NAMES (ie- column headers) or field VALUES (the data in the row/cell)? These 2 questions have very different answers. – RyanKDalton May 20 '13 at 18:38
  • Hey, I was trying to edit the name (column headers). The answer by blah238 sorted it out. Thanks for taking a look at it though. – HeidelbergSlide May 20 '13 at 18:59

You can do this using Calculate Value and a bit of Python:

  • Expression:


    (where Points is the value you actually want to use, I just guessed)

  • Code Block:

    def make_fieldname(input):
        return '_'.join(input.split(' ')[1:])[:10]

This will take your input value, split it at the spaces, strip off the first element (the year in your examples), join the rest with underscores, and finally truncate it at 10 characters to be safe.

Test results:

>>> make_fieldname("2001 Upland")
>>> make_fieldname("2001 Harvest")
>>> make_fieldname("2001 Deciduous")
>>> make_fieldname("1999 Party Time")
>>> make_fieldname("2013 A Really Long Year")
| improve this answer | |
  • Ah perfect! That did it, thanks so much for this. I really need to learn Python better, I tried Calculate Value for a while but just couldn't figure out the code to do this. Thanks again! – HeidelbergSlide May 20 '13 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.