[GIS] Unique name segment creation in ModelBuilder

arcgis-10.0arcgis-desktopmodelbuilder

Is it possible for us to give each output of a process a unique name segment (inline name). So for example I have a process that dissolves, then eliminates and buffers a single input file. I need to save the itermediate steps into a gdb.

So we have [TownNameX_slope]–Dissolve[\townDissolves.gdb\TownNameX_dissolve]–eliminate[townEliminates.gdb\TownNameX_eliminate] etc. then TownNameY etc.

So in a batch process I have to keep entering TownNameX for each output type. I know in iterators you can use %n but this is for just the output of one tool. Can we extend this to all the output where

%n=townnamex and then for dissolve the output is %n_Dissolve etc

I guess the other option is to run it in python in a "for" loop but I would prefer to stay in model builder as the reporting is easier.

This is similar to the question in Using ArcGIS ModelBuilder to perform In-line variable substitution for input data path?

Best Answer

I think Parse Path (a Model Builder-only tool) is what you're looking for, using the NAME option. Set it as a precondition for the rest of the Model, and use it to grab the town name from the filename of the input file. You can then use the output value name as an in-line variable in the other tools when naming the feature classes. For example, if you call the Parse Path output Output, your dissolved feature class could be created as townDissolves.gdb\%Output%_dissolve.

The only problem here is that Parse Path can only return a full feature class name (e.g. the previous feature class would be called "TownNameX_slope_dissolve" rather than just "TownNameX_dissolve") -- to do this you would need to write your own short Python script (and add it to a toolbox so that you could use it in your model) that gets the name doing something like this, after being passed the feature class as a parameter:

import arcpy, os
def GetName(input):
    Name = os.path.basename(input).strip("_slope")
    return Name
fc = arcpy.GetParameter(0)
arcpy.SetParameterAsText(1, GetName(fc))

(I haven't tested this, so not sure it works as-is.)

Related Question