ModelBuilder: Open shapefile using parsed filename

4386
10
Jump to solution
07-22-2015 12:44 PM
GaryHoffmann
New Contributor II

I'm trying to build a model that will iterate through a series of xyz text files, and clip each text file using a similarly named shapefile on a one-to-one basis. So example01.txt has a corresponding polygon shapefile, example01.shp, which will be used to clip it. So I've parsed out the filename, example01, but when I try to use that as the Clip Feature in the Clip tool, the model refuses to start, claiming that %filename%.shp does not exist. What am I missing? Is there a way to do this?

I've already tested a simpler model that will convert the text files to multipoint shapefiles, and that works on its own. But I can't get Arc to recognize that it needs to evaluate the filename variable prior to checking for the existence of the shapefile.

Thanks.

Model.png

Error.png

0 Kudos
1 Solution

Accepted Solutions
GaryHoffmann
New Contributor II

I contacted ESRI Tech Support and they confirmed that variables can't be used as inputs to a process. So you have to use Calculate Value with some python code to generate an intermediary output, which gives you more freedom to parse out particular substrings from a filename, anyway. Working version shown below. Thanks, everyone, for your help.

CalculateValue.png

WorkingArcModel.png

View solution in original post

10 Replies
DarrenWiens2
MVP Honored Contributor

Full disclosure, I don't use ModelBuilder very often, but this sounds like a job for a precondition.

0 Kudos
GaryHoffmann
New Contributor II

I've already got a precondition between the parsed filename and the ASCII 3D to Feature Class process.

EDIT: I've also tried making the parsed filename a precondition to the Clip process. Neither worked.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Oh, I think I see. Try using the full path to the shapefile. For example, C:/yourfolder/%FILENAME%.shp

Or, have you set the workspace environment?

0 Kudos
GaryHoffmann
New Contributor II

Yep, tried that, too. Both using %INPUT_FOLDER% as a variable and just manually entering the path. It's still saying %filename%.shp doesn't exist.

0 Kudos
DarrenWiens2
MVP Honored Contributor

How do you have the Parse Path tool set up? And, is it the Parse Path tool renamed, or a different tool called Parse Filename? I don't have anything called Parse Filename. What is the exact output value of FILENAME?

0 Kudos
GaryHoffmann
New Contributor II

It's Parse Path, set to Parse Type = NAME. I renamed it because I was playing around with parsing some paths and such. The exact output value should be, e.g. 840_0810 (UTM easting/northing values that were used to create the filenames). So 840_0810.txt should get turned into 840_0810_XYZ.shp (which works correctly in the simpler model I mentioned), which should then get clipped by 840_0810.shp (a polygon shapefile created prevsiously) to create 840_0810_CLIP.shp.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Try adding a second Parse Path tool to the Name variable, set to Path, and named "PATH". Then, change your Clip tool to look for:

%PATH%/%FILENAME%.shp

0 Kudos
ChrisDonohue__GISP
MVP Alum

A general suggestion - maybe try loading all your shapefiles into a File Geodatabase, then work against that.  I suggest this as you may be running up against a naming limit having to do with not just the filename but the path.  For example, if the combination of the filename and the path gets close to 255 characters, it can bomb out (even though the specs say it should work fine).

General information on Shapefiles

Geoprocessing considerations for shapefile output

Chris Donohue, GISP

0 Kudos
GaryHoffmann
New Contributor II

I can try that, but my path names are nowhere near 255 characters long.

0 Kudos