Select to view content in your preferred language

Adding fields to a shapefile/feature class - script

795
3
08-27-2010 12:00 AM
by Anonymous User
Not applicable
Hi Guys,

My tool needs to handle 2 scenario shapefiles. First will be the shapefile which has all required fields and second will be the shapefile that is missing a couple of the key fields.

What I'm after is a script I can use that will check the layer for these fields and add the missing fields if required. Idea was a simple button on the toolbar. Probably important that it only adds fields that are missing and doesn't overwrite anything that already exists.

Does anyone have any examples or guidance I could use?

Thanks

Kyle
Tags (3)
0 Kudos
3 Replies
by Anonymous User
Not applicable
In addition to my own posting, but as controls in the edit form will be linked to these potentially missing fields, will this cause the app to error, or would it still work but simply not be editable?

Thanks

Kyle
0 Kudos
EricHajek1
Regular Contributor
It's possible to append new fields onto shapefiles, but in the help they are referred to as "newly created shapefiles" so I don't know if you can do it with one that you're editing or one with data already in it. (See RecordSet -> Fields -> Append)
Your other question about having the form throw errors if the field doesn't exist: It probably won't, but you'll have to do something programmatically to handle having them / not having them, like programmatically saving the variables in question, or having seperate forms that fire depending on which shapefile is being edited.

Why do you need to do this though? Why not just have the fields already existing in both shapefiles, but remain empty for one scenario?
I'd rather right-click, delete empty fields post-field work everytime (this could be done during check-in if scripted so no one has to think about it) than hassle with this, since it just reeks of potential issues / possibility of not saving things.

Sorry, obviously this isn't a magic bullet to solve the issue, but I'd reconsider the reasons for the field dance. I've worked on projects where instead of reconsidering and changing things in the middle we plowed ahead with a flawed design that we could compensate for with programming effort. Trust me, simple and elegant is the way to go unless absolutely necessary.

Hope this helps,
Eric
0 Kudos
by Anonymous User
Not applicable
Eric,

Thanks for your response, and I fully agree that in an ideal world we could simply ensure that all the fields are present when taken into the field. The problem is that this tool will be used by a number of external agents who will already have the files in both the old format and the new format.

I'll look at appending the fields as you explained, but I worry that the checks to see whether the fields already exist may complicate things.

Thanks

Kyle
0 Kudos