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 want to add a field to my table in the FieldCalculator.

import arcpy
arcpy.AddField_management("veg8", "test", "TEXT")

An error message occured doing this and I figured out that I need to set a path to my table Like this for instance

C:\\user\\...

But, since I work in the Modelbuilder and the Model will be running on other computers, the path to the table will be a different one and I dont want to update all my paths everytime I run the model on a different computer. Is there a way to tell python to use the table to which the FieldCalculator is "connected"?

Thanks Chris

share|improve this question

closed as unclear what you're asking by radouxju, Mapperz Jun 26 at 14:50

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Can you clarify. You want to add a field in the FieldCalculator or Python Window? Also, if you're in the Field Calculator (inside the Attribute Table), why not just use the menu there to add a field? –  Branco Jun 26 at 13:15
    
I am in the ModelBuilder. We are building a model that shall run with different data and no furhter modification (or at least as less modifications in the model as possible). So feed it data, the model processes it, and then have some output. Thats why I cannot do in the Attributestable! I give the field calculator a shapefile as an input and want the fieldcalculator to process it in the modelbuilder. Since I am doing further calculations after adding the field, I want to add the field in the FieldCalculator. –  Stophface Jun 26 at 13:46
    
fieldcalculator does not add field, it runs a python script that evaluate a value within an existing field. What you show is an arcpy sample for a standalone script, and then you mention modelbuilder, so this is confusing. For adding a field in modelbuilder, use AddField. –  radouxju Jun 26 at 14:08
    
Yep. I wrote that part into the FieldCalculators 'CodeBlock'. I thought thats how you tell the FieldCalculator to look the upcoming instructions/syntaxes in the arcpy library up. I thought I can do it without the tool AddField right before I do calculations with the Calculator (which is python as well). –  Stophface Jun 26 at 14:28
    
FieldCalculator is meant for calculating within a field, there you may use python or VB code to perform some kind of calculation. If you want to Add a field through model builder drag the "add field" tool to the window, or use a stand alone python script. Your python code as it stands in your question does not belong in the field calculator. –  GISKid Jun 26 at 19:51
show 1 more comment

1 Answer

I would use in-line variable substitution, in ModelBuilder, so you can update all your paths simultaneously.

share|improve this answer
    
Sounds promising. I'll be gone until the end of next week but afterwards I'll have a look. Or I learn a little bit of python and write a script myself which I include into the modelbuilder :) –  Stophface Jun 26 at 21:46
add comment

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