2

I need to create a script in Python for use in ArcMap 10.

This script must be able to calculate a field from the shp currently selected in ArcMap.

Any ideas? I'm new to Python.

0

2 Answers 2

2

After running a tool in ArcMap you can go to the results window (Geoprocessing > Results) and right click on the finished tool. This will give the option to copy the Python code that you can then paste into your Python shell of choice. This is a great way to begin learning. After working with Python for a couple years now I still find myself doing this just to find out how the GP tool wants the parameters.

0
1

Unless I'm missing something from your question, you're just asking how to calculate [field2] from [field1] in the same shapefile.

If so, you just need to use the "Calculate Field" tool to do this. And if you just want to run this tool on a selected feature(s), all ArcGIS tools will only work on the selection set if one exists.

ArcGIS Help has python code examples that show exactly how to do it in Python.

Look in the "Code Sample" section about halfway down help. Their [generalized] example is:

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.AddField_management("<in_table>", "<field>", "TEXT", "", "", "20")
arcpy.CalculateField_management("<in_table>", "<field_to_calc>",
                                <field_with_values>, "PYTHON")

If that is all you are after, it's pretty simple.

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.