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.

How do I integrate a in-line variable from modelbuilder into a python script? Specifically, I'm using an iterator, and I'm trying to include the 'name' variable in a python script. I believe the problem is on step four, when I add it to the model as a a script (as shown here).

Script code I'm trying to include looks like this:

pop_rank = 1
rows = arcpy.UpdateCursor ("path_to_dataset", "", "", "", "pop A")
for row in rows:
    row.setValue("RANK", pop_rank)
    pop_rank += 1
    rows.updateRow(row)

Specifically, I'd like to make the "path_to_dataset" into the 'Name' variable from the iterator.

I can pull the path using the 'parse path' model builder only tool, but I'm not sure how to feed that into the Python Script.

share|improve this question
1  
Suggestions for improvement of this Question are to include a screenshot of relevant parts of your model, a copy of the Parameters tab for Properties of that model and the GetParameter part of your Python script. However, these should not just be added without trying to make the question more understandable to anyone reading it, so please read and re-read it as if you are someone coming fresh to the issue. –  PolyGeo Oct 28 '12 at 1:11
add comment

2 Answers 2

Hopefully the following recommendations will give you some ideas:

# Local variables
input = arcpy.GetParameterAsText(0)      # Set data type: featureclass, shapefile, or table 
pop_rank = arcpy.GetParameterAsText(1)   # Set as data type: SQL expression

rows = arcpy.UpdateCursor (input, "", "", "", "pop A")
for row in rows:
    row.setValue("RANK", pop_rank)
    rows.updateRow(row)
share|improve this answer
add comment

This works in the python window, and works when I run it. But I'm not quite sure why or how.

# Local variables
input = arcpy.GetParameterAsText(0)      # Set data type: featureclass, shapefile, or table 
pop_rank = 1

rows = arcpy.UpdateCursor (input, "", "", "", "GiPValue A")
for row in rows:
    row.setValue("RANK", pop_rank)
    pop_rank += 1
    rows.updateRow(row)
share|improve this answer
add comment

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.