2

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.

1
  • 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
    Commented Oct 28, 2012 at 1:11

2 Answers 2

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)
1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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