2

I have the following code below to clean up a table to ensure that phone numbers and emails are entered in correctly, and am trying to debug my code. I am new at Arcpy, so I am still trying to figure out why I am getting a error for my MakeFeatureLayer() function... Although I think my query for phone numbers may be in correct as well.

Error:

ERROR 000732: Input Features: Dataset 
  \\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\Con‌​tacts 
does not exist or is not supported Failed to execute (MakeFeatureLayer)

Script:

import arcpy, os

contacts = r'\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\Contacts'
comTrkr = r'\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\ComTrkr'
GISTrkr = r'\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\GISTrkr'

gdb = "\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb"
  arcpy.MakeTableView_management(contacts,"Contacts_tbl")

  arcpy.MakeTableView_management(contacts,"Contacts_tbl")
arcpy.env.overwriteOutput=True

#arcpy.Selectbyattribute. All Null Updated to New

#Selectbyattribute QA/QC output table Contact_Status1
arcpy.SelectLayerByAttribute_management("Contacts_tbl", "NEW_SELECTION", "Contact_Status1 IS NULL" )
arcpy.CalculateField_management("Contacts_tbl", "Contact_Status1", '"NEW"' )
#arcpy.SelectLayerByAttribute_management(in_table, "CLEAR_SELECTION")  needed?

#Create output table to edit in Arcmap for Both Email fields
Contact_Email_Output = os.path.join(gdb,os.path.basename(gdb) + '_Contact_Email')
arcpy.SelectLayerByAttribute_management("contacts", "NEW_SELECTION", "Contact_Email LIKE '%@%'" )
arcpy.CopyRows_management("Contacts_tbl", Contact_Email_Output)
#arcpy.AddField_management(Contact_Email_Output, "Editor", "TEXT")
#arcpy.EnableEditorTracking_management(Contact_Email_Output,'','','','ET_Date', "ADD_FIELDS")

arcpy.AddMessage("Contact_Email Table created, now on to Agency_Email")

Agency_Email_Output = os.path.join(gdb,os.path.basename(gdb) + '_Agency_Email')
arcpy.SelectLayerByAttribute_management("contacts", "NEW_SELECTION", "FROM contacts WHERE Agency_Email IS LIKE %@% " )
arcpy.CopyRows_management("Contacts_tbl", Agency_Email_Output)
#arcpy.AddField_management(Contact_Email_Output, "Editor", "TEXT")
#arcpy.EnableEditorTracking_management(Agency_Email_Output,'','','','ET_Date', "ADD_FIELDS")

#String length for phone number.
Contact_Phone_Work_Output = os.path.join(gdb,os.path.basename(gdb) + '_Contact_Phone_Work_Email')
arcpy.SelectLayerByAttribute_management("contacts", "Contact_Phone_Work", "NEW_SELECTION", "FROM contacts WHERE LEN([Contact_Phone_Work]) = 12")
arcpy.SelectLayerByAttribute_management("contacts", "Contact_Phone_Work", "NEW_SELECTION", "FROM contacts WHERE Contact_Phone_Work IS LIKE '%-%' ")
arcpy.CopyRows_management("Contacts_tbl", Contact_Phone_Work_Output)

Agency_Phone_Email_Output = os.path.join(gdb,os.path.basename(gdb) + '_Agency_Phone_Email')        
arcpy.SelectLayerByAttribute_management("contacts", "Contact_Phone_Work", "NEW_SELECTION", "FROM contacts WHERE LEN(Agency_Phone_Work) = 12")
arcpy.SelectLayerByAttribute_management("contacts", "Contact_Phone_Work", "ADD_SELECTION", "FROM contacts WHERE Agency_Phone_Work IS LIKE '%-%' ")
arcpy.CopyRows_management("Contacts_tbl", Agency_Phone_Output) 
  • If you are using Windows, you need to specify the correct path which includes the drive letter (e.g. r'C:\temp\path\to\your.gdb\fc') – Aaron Mar 6 '17 at 23:14
  • Please use the edit button beneath your question to revise it with where you are currently stuck. Perhaps look into using MakeTableView instead of MakeFeatureLayer. – PolyGeo Mar 6 '17 at 23:14
  • 1
    If the "Contacts" layer that you are referencing is only an Attribute table, then the function will fail. A FeatureLayer can only be created out of a FeatureClass of some form, whether GDB, shapefile, etc, not a Standalone Table. – Get Spatial Mar 6 '17 at 23:26
  • 2
    Cross-posted as stackoverflow.com/q/42636761/820534. Please do not cross-post. – PolyGeo Mar 7 '17 at 11:48
4

To expand on @GetSpatial's comment, if your Contacts is a Table and not a Feature Class, you will get the 000732 error Con‌​tacts does not exist or is not supported Failed to execute (MakeFeatureLayer).

Try changing the arcpy.MakeFeatureLayer() for a arcpy.MakeTableView()

gdb = r"\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb"
arcpy.MakeTableView_management(contacts,"Contacts_Lyr")

The rest of your script should work fine using a Table View rather than a Feature Layer.

Note I have left the name "Contacts_Lyr" here as you reference this multiple times further in your script. You could rename this to make it not appear to be a Layer, but you will need to rename all instances where Contacts_Lyr is referenced.


In response to your comments, I have updated your entire script

import arcpy, os

contacts = r'\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\Contacts'
comTrkr = r'\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\ComTrkr'
GISTrkr = r'\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\GISTrkr'
gdb = r"\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb"

arcpy.env.overwriteOutput=True

contactsTblVw = arcpy.MakeTableView_management(contacts,"Contacts_tbl")

#arcpy.Selectbyattribute. All Null Updated to New
#Selectbyattribute QA/QC output table Contact_Status1
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "Contact_Status1 IS NULL" )
arcpy.CalculateField_management(contactsTblVw, "Contact_Status1", '"NEW"' )

#Create output table to edit in Arcmap for Both Email fields
Contact_Email_Output = os.path.join(gdb, 'Export_Contact_Email') # To produce output named \\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\Export_Contact_Email
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "Contact_Email LIKE '%@%'" )
arcpy.CopyRows_management(contactsTblVw, Contact_Email_Output)
#arcpy.AddField_management(Contact_Email_Output, "Editor", "TEXT")
#arcpy.EnableEditorTracking_management(Contact_Email_Output,'','','','ET_Date', "ADD_FIELDS")

arcpy.AddMessage("Contact_Email Table created, now on to Agency_Email")

Agency_Email_Output = os.path.join(gdb, 'Export_Agency_Email')
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "FROM contacts WHERE Agency_Email LIKE %@% " )
arcpy.CopyRows_management(contactsTblVw, Agency_Email_Output)
#arcpy.AddField_management(Contact_Email_Output, "Editor", "TEXT")
#arcpy.EnableEditorTracking_management(Agency_Email_Output,'','','','ET_Date', "ADD_FIELDS")

#String length for phone number.
Contact_Phone_Work_Output = os.path.join(gdb, 'Export_Contact_Phone_Work_Email')
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "FROM contacts WHERE LEN([Contact_Phone_Work]) = 12")
arcpy.SelectLayerByAttribute_management(contactsTblVw, "ADD_TO_SELECTION", "FROM contacts WHERE Contact_Phone_Work LIKE '%-%' ")
arcpy.CopyRows_management(contactsTblVw, Contact_Phone_Work_Output)

Agency_Phone_Email_Output = os.path.join(gdb, 'Export_Agency_Phone_Email')        
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "FROM contacts WHERE LEN(Agency_Phone_Work) = 12")
arcpy.SelectLayerByAttribute_management(contactsTblVw, "ADD_TO_SELECTION", "FROM contacts WHERE Agency_Phone_Work LIKE '%-%' ")
arcpy.CopyRows_management(contactsTblVw, Agency_Phone_Output)

You may need to adjust how you select your phone numbers, as I'm not sure I follow what you're trying to do here, but I think I've corrected the inputs and outputs as required to get past the errors you mentioned.

  • ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Layer Name or Table View: Dataset Contacts_Lyr does not exist or is not supported Failed to execute (SelectLayerByAttribute). – Purplepeopleeater Mar 7 '17 at 14:56
  • @winscott68 That's because you gave your Table View a different name. In your edit above you've used "Contacts_tbl". If you don't want to update the rest of your code, you'll still need to use "Contacts_Lyr". If you prefer to change the name to "Contacts_tbl" then you'll need to change every instance of "Contacts_Lyr" as well. – Midavalo Mar 7 '17 at 16:14
  • Now I get a invalid expression on Select by Attribute: File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 7221, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute). – Purplepeopleeater Mar 7 '17 at 16:29
  • @winscott68 remove the square brackets [ ] from your expression - "[Contact_Status1] IS NULL" should be "Contact_Status1 IS NULL" as you are using a File geodatabase not a personal geodatabase. – Midavalo Mar 7 '17 at 16:44
  • ok I removed all brackets within my expression. Now it seems to not like the calculate field expression: "Contact_Status1", "NEW" ) File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 3457, in CalculateField raise e ExecuteError: ERROR 999999: Error executing function. Expected identifier Failed to execute (CalculateField). – Purplepeopleeater Mar 7 '17 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.