I am trying to create a script that will automate a Feature Class to Feature Class OR Feature Class to File Geodatabase Conversion. I want to save this in a folder as a back up once a week in case I lose my current data for any reason or need to revert to that download date. So far I have the following code just for the FC to FC operation, and am recieving the error that follows.:
import arcpy arcpy.env.workspace = "https://services.arcgis.com/T2graiaSQnlmwwmp/arcgis/rest/services/Target_Address_7_6_Backup/FeatureServer" arcpy.FeatureClassToFeatureClass_conversion("Target Address New", "C:\\Users\vmrenfor\Consumers Folders\VSR\BackupExports\VSR Back up\VSR Back up.gdb", "Target_Adrress_12_10_2018") Traceback (most recent call last): File "<string>", line 5, in <module> File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 860, in FeatureClassToFeatureClass raise e File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 857, in FeatureClassToFeatureClass retval = convertArcObjectToPythonObject(gp.FeatureClassToFeatureClass_conversion(*gp_fixargs((in_features, out_path, out_name, where_clause, field_mapping, config_keyword), True))) File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 496, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Output Location: Dataset C:\Users mrenfor\Consumers Folders\VSR\BackupExports\VSR Back up\VSR Back up.gdb does not exist or is not supported Failed to execute (FeatureClassToFeatureClass).
Any thoughts on how I can fix this error would be appreciated. I would then like this to be run each subsequent week, naming the file "Target_Address_{Current Date}.
Here is what I ran and was returned:
import arcpy
import datetime
now = datetime.datetime.now()
arcpy.env.workspace = "https://services.arcgis.com/T2graiaSQnlmwwmp/arcgis/rest/services/Target_Address_7_6_Backup/FeatureS..."
arcpy.FeatureClassToFeatureClass_conversion("Target Address New",
r"C:\Users\vmrenfor\Consumers Folders\VSR\BackupExports\VSR Back up\VSR Back up.gdb",
"Target_Address_{}".format(now.strftime("%m_%d_%Y"))
File "<string>", line 8
"Target_Address_{}".format(now.strftime("%m_%d_%Y"))
^
SyntaxError: unexpected EOF while parsing
It looks like you are missing a parentheses at the end of your function call.
I added the parentheses at the end on the function and that allowed it script to run. The resulting Feature Class does not contain the attachments though, where as when I ran the script without the date time part the attachments all came through.
Any thoughts?
Make sure Maintain Attachments (Environment setting)—Geoprocessing | ArcGIS Desktop is set correctly.
>>> Import arcpy
>>> Import datetime
>>> now = datetime.datetime.now()
>>> arcpy.env.workspace = "https://services.arcgis.com/T2graiaSQnlmwwmp/arcgis/rest/services/Target_Address_7_6_Backup/FeatureS..."
>>> arcpy.TeatrueClassToFeatureClass_conversion("Target Address New",
r"C:\Users\vmrenfor\Consumers Folders\VSR\BackupExports\VSR Back up\VSR Back up.gdb",
"Target_Address_{}".format(now.strftime("%m_%d_%Y")))
>>> arcpy.env.maintainAttachments = True
Is this what my script should look like? Attachments are still not coming through.
Setting the environment variable after you have run the tool isn't going to do any good if the environment variable is the issue.
>>> Import arcpy
>>> Import datetime
>>> now = datetime.datetime.now()
>>> arcpy.env.workspace = "https://services.arcgis.com/T2graiaSQnlmwwmp/arcgis/rest/services/Target_Address_7_6_Backup/FeatureS..."
>>> arcpy.env.maintainAttachments = True
>>> arcpy.TeatrueClassToFeatureClass_conversion("Target Address New",
r"C:\Users\vmrenfor\Consumers Folders\VSR\BackupExports\VSR Back up\VSR Back up.gdb",
"Target_Address_{}".format(now.strftime("%m_%d_%Y")))
Sorry, I'm not a coder, I just script a lot. So maybe that is better?
I don't know how you're getting anything to come through. I've never know to set the arcpy.env.workspace to a Feature Service will allow you to download the data. I tried the following:
import arcpy
import datetime
now = datetime.datetime.now()
arcpy.env.workspace = "https://services.arcgis.com/T2graiaSQnlmwwmp/arcgis/rest/services/Target_Address_7_6_Backup/FeatureS..."
arcpy.env.maintainAttachments = True
arcpy.FeatureClassToFeatureClass_conversion("Target Address New", r"C:\Temp\Python\Test.gdb", "Target_Address_{}".format(now.strftime("%m_%d_%Y")))
But receive an error:
ERROR 000732: Input Features: Dataset Target Address New does not exist or is not supported
Failed to execute (FeatureClassToFeatureClass).
I ran the following tool:
And this worked successfully, except for the attachments. Sync will need to be enabled for attachments to be download with the referenced tool:
Here is a helpful link on how to post code in GeoNET. It's kind of hidden.
Also, you are specifying a feature service for your workspace:
arcpy.env.workspace = "https://services.arcgis.com/T2graiaSQnlmwwmp/arcgis/rest/services/Target_Address_7_6_Backup
If you are specifying a feature class for the first parameter in the Feature Class to Feature Class function, your arcpy.env.workspace should be set to the geodatabase it resides in.