Select to view content in your preferred language

Reorder Fields in a TableView Using Python

3807
6
07-19-2010 01:05 PM
ElizaLedwell
New Contributor
Hi,

I am trying to write a python script that will create a table view from the attribute table of a shapefile and then export it as .dbf file. I wrote a script that does exactly that but I also need to order the fields in the .dbf file in a certain order that does not match the input shapefile.

How could I do this????
I am using ArcMap 9.3.1 with ArcView permissions

Thanks for any help,

Eliza Ledwell
0 Kudos
6 Replies
JoelCalhoun
New Contributor III
Eliza,

I ran across this script by Chris Snyder a while back, it might work for you.

http://arcscripts.esri.com/details.asp?dbid=16771



Joel
0 Kudos
ChrisSnyder
Regular Contributor III
Here's two different methods to reorder fields via Python:

1. Add some dummy fields, calc over the values (FIELD1_DUMMY = FIELD1_ORIG), delete the original fields, add the fields you want in the order you want, calc over the values (FIELD1_ORIG = FIELD1_DUMMY), then delete the dummy fields.

2. Build a blank  table, add the fields you want to retain in the order you want, then run the append tool to append the original records into the blank table with the reordered fields. As long as the field names/types are exactly the same, use the NO_TEST option, otherwise you have to use the ugly field mapping object which is a real pain.
0 Kudos
JoelCalhoun
New Contributor III
If you know the specific order you want your output table items to be you can manually order the items in your code with the FeatureClasstoFeatureClass tool. 

To get the proper syntax I recommend setting up the tool in Modelbuilder and exporting it to Python.  Then simply reorder the fields in the Python code manually.  Your output will be a new shp with your reordered fields.


Joel
0 Kudos
ElizaLedwell
New Contributor
Got it! Thank you for your help.
0 Kudos
BobRoberts
New Contributor
I am trying to write a python script that will create a table view from the attribute table of a shapefile and then export it as .dbf file. I wrote a script that does exactly that


Eliza,
I saw your post and I am trying to do exactly what you said you had created; creating a table view from a shapefile and exporting as a .dbf.

Could you maybe share a snippet of your code of how you did that?

Thanks,

BR
0 Kudos
RyanKelley
New Contributor II
0 Kudos