I attempted to include a model parameter for the workspace, rather than use the parse path tool (show in the image).I am trying to calculate a field using part of the feature class path name (specifically, the last three characters of the geodatabase name). Is this possible? I've tried using the parse path tool and including the value as an inline variable subsitution with the VB string right function. Perhaps a more complicated Python script is neccessary?

  • Can we see the exact expression you're using for the calculation, and/or a screenshot of the relevant portion of your model? – nmpeterson Jun 12 '14 at 18:51
  • Please clarify your question, you are referring to feature class path name, but say you need last three characters of the geodatabase name (a little confusing). – artwork21 Jun 12 '14 at 19:32
  • I am trying to calculate a field to include the last three characters of the geodatabase the feature class is located (so 7 characters really including the extension). So if the geodatabase is named 'Sample Geodatabase Name STW.gdb' I want the field to include the attribute 'STW.gdb'. – Alexa Jun 12 '14 at 19:36

with Python (you'll need to define workspace, the script loops on all feature classes in the workspace and update the field with the last three characters of its name :

fcs = arcpy.ListFeatureClasses()
for fc in fcs:
    arcpy.CalculateField_management(fc, "field_to_update", "'" + fc[-3:] + "'", "PYTHON")

EDIT : for the gdb name , the expression would be

expression = arcpy.Describe(fc).catalogPath.split(".gdb")[0][:-3]
  • While this isn't technically a ModelBuilder answer, you could turn this into a short Python script tool (i.e. add it to a toolbox) and incorporate it into your model. The tool would have to accept the feature class/layer and the field name as inputs. – nmpeterson Jun 12 '14 at 19:27
  • Thanks for the input! I don't know Python very well, but I'll take this information and see if I can make it work. – Alexa Jun 12 '14 at 19:33
  • It sounds like Alexa needs the last three characters of the geodtabase name not the feature class(s), "(specifically, the last three characters of the geodatabase name)". – artwork21 Jun 12 '14 at 19:33
  • That is correct. – Alexa Jun 12 '14 at 19:50
  • Thank you! I got it to work using Python. The script is as follows: – Alexa Jun 12 '14 at 23:39

Maybe just make your geodatabase workspace a required parameter for the model, and then assign that value to a variable, from this you could then pull the desired characters as you stated in your question.

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.