Add & Calculate Multiple Fields

4520
8
11-01-2012 02:44 AM
MarkYoung
Occasional Contributor
Hi,
I have a model whereby I add a field and calculate that value. Thing is I need to do this a three times on the one feature class and the model is getting a bit drawn out in space and processing time. Is there a way to use the add field function but specify three fields rather than a separate add field function every time?
Any help would be appreciated.
Thanks in advance,
Mark
0 Kudos
8 Replies
by Anonymous User
Not applicable
I do not think there is a way to add multiple fields with one tool because you have to set the properties for each field that you add.  I think you will still have to add each field individually. 

However, if you are familiar with Python, you can speed up the calculation process (especially if you have 10.1!) with the use of an update cursor for your feature class.  This will eliminate the need to use the calculate field tool 3 different times.
0 Kudos
MarkYoung
Occasional Contributor
Hi,
Thank you for the reply. Seems I will have to create the fields one by one for the time being. Model works really well but its very slow to open the model on other people's PC's and there is no data local to my PC. I thought that if I exported the model to python then added it as a script it might be quicker. Is this possible in 10.0? When I try and create a new UI button to add the python script to ArcMap it doesn't work as the editor is for VB. Alternatively any ideas on how to speed up opening the model would also be appreciated. Takes around 30 seconds to open
Thanks
Mark
0 Kudos
by Anonymous User
Not applicable
Hi Mark,

Yes this can be done with 10.0.  You need to right click on the Model and Export to Python Script.  Once you have done this, it creates a stand alone Python script that you dont need to access from arcmap.  Find the location on disk where you put the Python file and right click on that and choose "Edit with IDLE".  This is where you can play with the script. 

By using Python, you could definitely speed up this process by using update cursors rather than the field calculator (if not joined tables).  Adding multiple fields can also be sped up if they are the same type (you can use a tuple or list to store the field names with a for loop to add each field name in the list). 

However, this will be tough to swallow if you have no prior Python\programming experience. If this is the case it may be best to stick with model builder.  There are ways that you can set the model to run as a scheduled task, so if it takes a long time to run perhaps you could have it working at night when you are not in the office?  If your model works, there's no need to re-invent the wheel.  As for the slow opening time, I think this is probably because it is not local.  I do not have any ideas about that.  Hope this helps a little.
0 Kudos
KimOllivier
Occasional Contributor III
You don't have to add fields one at a time. Use the FeatureClasstoFeatureClass tool and a Fieldmap. This does not require programming and can be included in your model. You can define new fields there.

While you are there, maybe you can merge the source data so you would not have to calculate the fields either. It is very fast if all you were doing was doing a join and calculate which should be avoided because it is very slow and often leaves the fields blank.
0 Kudos
MarkYoung
Occasional Contributor
Shall look into that suggestion
Thanks
0 Kudos
RussellBrennan
Esri Contributor
0 Kudos
MarkYoung
Occasional Contributor
Hi Russell,
I will have a look at this as well. I am up and running for the time being but the model could definitely be a bit slicker. Reason for adding fields is due to the fact I am using data from another live database and unable to alter the field structure for my dissolve process in the model so I have to add a common field used by the dissolve process every time the model is run. I ended up copying the four feature classes to our ESRI Sde instead of adding field 'on the fly' every time. Its not ideal as there are now two versions of the data which means a double update, infrequent as they are.Table to fields looks good. Will post back when I re-build the appropriate sections of the model.
Thanks for your help
Mark
0 Kudos
jasonross2
New Contributor
I have a similar problem, but have solved much of it except the output.

The way I approached it was to make a FC with the fields I want to add to existing FC's.  In my case I am adding a bunch of default fields and values to existing data to import the data into HAZUS-MH via their CDMS tool.  Long and short of that is there's usually 15-20 fields that need to get added, then specific default values based on what type of facility i am importing.

I start the model with a merge of the existing FC and the empty-new-fields FC, then I use geoprocess Calculate Field, changing the input field and expression to a list of the added fields and their associated values.

Running the model I do not get any errors, and the app says it completed OK, but I end up with no output FC, no results.  If I troubleshoot the process with a single value added to a single new field, it works and I get output, but this way I would have to daisy-chain the outputs to keep adding a new value to each new field, and get an outputted file each time.  I know these can be temporary, but they would also slow the process way down, and make it hard to manage changes as the values are spread across a bunch of parameter objects, not a single list.

Anyone know a solution to why i am not getting a single output FC at the end of the model with all my new values populated into the new fields? 

Thanks.
0 Kudos