Tool for generating Feature Class including field names/type...

3834
14
07-22-2015 10:26 AM
TravisLathrop1
New Contributor III


I am trying to build a tool that will generate a feature class and then populate the fields with the correct column name and format based off a Excel file.  Has anyone had any luck doing this before?  I'm looking for model or code examples if anyone happens to have anything similar.  Has anyone seen any tutoria documents online that do this type of request?  That could help also.

Thanks in advance!

0 Kudos
14 Replies
TravisLathrop1
New Contributor III

The script will run but its not generating the data the way I had hoped.  It doesn't look like any of the values in column A in the CSV file were added as column just the values for column B.  Here is what the attribute table for the new FC looks like after running the tool:

FCStructure.png

I want the new FC to have columns based on the data in column A.

FCColumns.png

What do I need to change??

0 Kudos
DarrenWiens2
MVP Honored Contributor

The arguments for AddField are, (in_table, field_name, field_type), in that order. Check syntax section here.

arcpy.AddField_management(fc, row[0], fieldtypes[row[1][:4]])

fc = the input table

row[0] = the field name (the first column in your spreadsheet. E.g. 'geodb_oid')

row[1][:4] = the first four characters of the second column in your spreadsheet (e.g. 'inte')

fieldtypes[row[1][:4]] = the value associated with the key 'inte' (e.g. 'LONG')

0 Kudos
TravisLathrop1
New Contributor III

Thanks for your help...almost have it now!
TL

0 Kudos
AlexZhuk
Occasional Contributor III

I created a small/quick/convenient model for myself.

Model1.PNG

----

Model2.PNG

0 Kudos
DarrenWiens2
MVP Honored Contributor

Hmmm. Is this in the right place?

0 Kudos