I have difficulties to find a straightforward solution for, as i think, a simple task. In a script tool the user has to choose a location to save a table. I used a Table typed input field in the tool parameters, so in my script a get a parameter containing a path and name for the table. In my script i want to use CreateTable_management and AddField_management to structure the table for my needs. Later i use an insert cursor to fill the table.
The problem is, that, depending on what parameter value the user gave, i got different table formats, eg. the user selects a folder and a name without an extension, CreateTable builds an info table, within a geodatabase it builds a gdb table, with folder and extension .dbf it creates dbase table - i don't know how much possibilities there may be further. Creating a table produces different, automatically created fields:
- gdb: ObjectID
- dbf: OID, Field1
- info: Rowid, OBJECTID, FIELD1
I don't need these automatically created fields, i want my own structure, so : can i suppress the creation of those fields?
What would be a straightforward solution, working with tables in a script tool. I attached an example with code.
I can't doing it that way, but there is another way, i'm sure...
Just found this tips: Adding Fields: Performance Tips | ArcPy Café
would it help to make a in memory template first? If i can get over the creation of Field1, i would be lucky. So the problems with different field names ObjectId, OID, OJECTID will still exist and the info format has this additional Rowid-Field, can i ignore them when using an insert cursor?
You are pointed in the right direction, i.e., create an in-memory table and use it as a template.
Regarding ObjectID, OID, OBJECTID fields, they are "system" fields that aren't directly managed by the user. Although you can retrieve the values in cursors, you won't be able to modify them. For insert cursors, a value will be automatically populated for you when you insert a new record.