1

I am very, very new at python and am trying to put together a tool that can be run on an enterprise geodatabase that will add a series of fields to each feature class. So far I have only been able to get it to work locally on my C and D drives, so I think I must be missing something as it won't work on the network drives or the enterprise gdb.

The code I have is below:

import arcpy

#get Input feature class/classes - Multivalues enabled for this script
fc = arcpy.GetParameterAsText(0)
tbl = arcpy.GetParameterAsText(1)

#Split multivalues
fclist = fc.split(";")
tbllist = tbl.split(";")

#Add additional source fields
for fc in fclist:
    arcpy.AddGlobalIDs_management(fc)
    arcpy.AddField_management(fc, "Source", "TEXT", "", "", "255", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "SourceObjectID", "TEXT", field_length = 20)
    arcpy.AddField_management(fc, "SourceDate", "DATE")
    arcpy.AddField_management(fc, "SupplyDate", "DATE")     
    arcpy.AddField_management(fc, "SourceDataset", "TEXT", field_length = 100)
    arcpy.AddField_management(fc, "SourceLayer", "TEXT", field_length = 100)
    arcpy.AddField_management(fc, "SourceAccuracy","TEXT", field_length = 50, field_domain = "GBL_GeomCaptureMethod")
    arcpy.AddField_management(fc, "SourceMetadata", "TEXT", field_length = 100, field_domain = "GBL_SourceAccuracy")
    arcpy.AddField_management(fc, "AssetOwner", "TEXT", field_length = 50)
    arcpy.AddField_management(fc, "AssetID", "TEXT", field_length = 20)
    arcpy.AddField_management(fc, "Comment", "TEXT", field_length = 255)
    arcpy.AddField_management(fc, "CreatedBy", "TEXT", field_length = 50)
    arcpy.AddField_management(fc, "CreatedDate", "DATE")
    arcpy.AddField_management(fc, "ModifiedBy", "TEXT", field_length = 50)
    arcpy.AddField_management(fc, "ModifiedDate", "DATE")


for tbl in tbllist:
    arcpy.AddGlobalIDs_management(tbl)
    arcpy.AddField_management(tbl, "Source", "TEXT", field_length = 100, field_domain = "GBL_Source")
    arcpy.AddField_management(tbl, "SourceObjectID", "TEXT", field_length = 20)
    arcpy.AddField_management(tbl, "SourceDate", "DATE")
    arcpy.AddField_management(tbl, "SupplyDate", "DATE")     
    arcpy.AddField_management(tbl, "SourceDataset", "TEXT", field_length = 100)
    arcpy.AddField_management(tbl, "SourceLayer", "TEXT", field_length = 100)
    arcpy.AddField_management(tbl, "SourceAccuracy","TEXT", field_length = 50, field_domain = "GBL_GeomCaptureMethod")
    arcpy.AddField_management(tbl, "SourceMetadata", "TEXT", field_length = 100, field_domain = "GBL_SourceAccuracy")
    arcpy.AddField_management(tbl, "AssetOwner", "TEXT", field_length = 50)
    arcpy.AddField_management(tbl, "AssetID", "TEXT", field_length = 20)
    arcpy.AddField_management(tbl, "Comment", "TEXT", field_length = 255)
    arcpy.AddField_management(tbl, "CreatedBy", "TEXT", field_length = 50)
    arcpy.AddField_management(tbl, "CreatedDate", "DATE")
    arcpy.AddField_management(tbl, "ModifiedBy", "TEXT", field_length = 50)
    arcpy.AddField_management(tbl, "ModifiedDate", "DATE")

When I run this script I get the following error:

Executing: AddSourceMetadata 'Database Connections\ADMIN_TEST_SpatialMaint.sde\SpatialMaint_Test.CORPORATE.abcd' #
Start Time: Tue Mar 08 12:57:50 2016
Running script AddSourceMetadata...
Failed script AddSourceMetadata...

Traceback (most recent call last):
  File "T:\Scripts\ArcPy\AddSourceMetadata.py", line 14, in <module>
    arcpy.AddField_management(fc, "Source", "TEXT", "", "", "255", "", "NULLABLE", "NON_REQUIRED", "")
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 3246, in AddField
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Table: Dataset 'Database Connections\ADMIN_TEST_SpatialMaint.sde\SpatialMaint_Test.CORPORATE.abcd' does not exist or is not supported
Failed to execute (AddField).


Failed to execute (AddSourceMetadata).
Failed at Tue Mar 08 12:57:53 2016 (Elapsed Time: 2.58 seconds)

All the fc's that I have put into the tool so far have been a straight drag and drop, so everything is spelt correctly and it actually does exist!

5
  • 1
    Can you please add any error messages to your question?
    – Midavalo
    Commented Mar 8, 2016 at 0:02
  • 1
    Also are you adding layers from ArcMap or feature classes direct from the geodatabase (in your fc = arcpy.GetParameterAsText(0))?
    – Midavalo
    Commented Mar 8, 2016 at 0:03
  • At the moment your code includes try/except statements. I think these should not be included in code snippets posted here because they often mask the error messages that Python provides to help you.
    – PolyGeo
    Commented Mar 8, 2016 at 0:08
  • As for the error I get when trying to run on an enterprise geodatabase, I consistently get error 000732. Not sure, but maybe my file path is too long? Is that possible?
    – hlane
    Commented Mar 8, 2016 at 2:11
  • Error 000732 is Dataset does not exist or is not supported - have you checked that the feature class exists and there are no typos? What are the values you've put into your fc and tbl parameters? Please edit your post to add to your question.
    – Midavalo
    Commented Mar 8, 2016 at 3:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.