Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm new to modelbuilder and python. I have used modelbuilder to iterate through all rows in a shapefile (Points), process them, and produce a seperate output shapefile for each row. The filename is generated using an inline variable (I think that is the correct terminology). i.e. all output files have identical filenames except that the value of the PointID from the original input file is appended to the filename to enable them to be distinguished. This works fine.

I've also written a python script to take the above output files from the model one at a time and do additional processing. At present the input filename is hard coded into the script (i.e. I have to edit the script to change the input filename each time I run it). Again this works fine while just processing a single file. However, I want to integrate the model and the python script so that I can run the script for each row in the original feature class automatically.

My question is therefore, how do I replace the hard coded name of the input file with a variable in the python script and how do I pass the filename to the script.

Any assistance will be appreciated.

Thanks

Steve

share|improve this question
1  
Your best bet is to export your model as a python script and incorporate your second script into it. Otherwise, you could use python to get only a portion of the file name and store that as a variable. –  Roy Jul 19 '12 at 11:23

1 Answer 1

In the script make point feature class variable provided as parameter:
inputPointFC = arcpy.GetParameterAsText(0)

Then create a script tool with one input parameter which uses your single point feature class as Default property. This feature class name should be provided with inline variable: PointFC_%Value%, where Value is name of iterator output.
Here's a picture example:
enter image description here

share|improve this answer
    
Many thanks. Sorry for delay in responding - got sidetracked onto something else. –  Steve Dugdale Jul 25 '12 at 9:33
    
Many thanks @Marcin. The parameter passed in included the complete filepath rather than just the filename so I had to add some code to strip out the filepath (which was already assigned to the variable "workspace" as an environment setting). In case it's useful to others my code to do that is posted below. filepath_length = len(env.workspace) + 1 # Add 1 as no backslash at end of "env.workspace" which in practice seperates filepath from filename filename_start = filepath_length filename_end = len(inDataset_string) filename = inDataset_string[filename_start:filename_end] –  Steve Dugdale Jul 25 '12 at 9:46
    
If you place your script inside your model, you can use the Parse Path model tool with an input model parameter for your original feature class, to extract just the name of the fc and use that as an inline variable for the rest of your processes. –  Arabella Jul 26 '12 at 6:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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