Arcpy - FeatureClassToFeatureClass

5427
10
Jump to solution
11-25-2015 06:29 AM
TrilliumLevine1
Occasional Contributor

Hello All,

I have a dictionary with a list of feature class paths (keys) and destination feature datasets (values) that I'm trying to use to do a batch FeatureClassToFeatureClass operation with.  No matter what I've tried, however, I keep getting the same error when I run the script:

Here is the code I'm running to do this:

for key, value in FCFDdict.iteritems():
        inFC = str(key)
        destination = str(value)
        outFC = str(os.path.basename(key))
        arcpy.env.workspace = destination
        arcpy.FeatureClassToFeatureClass_conversion(inFC, destination, outFC)

My dictionary is populated with unicode strings, and looks like this:

{
u'C:\\Scripts\\Redefine Projection\\MyGeodatabase.gdb\\FD_A\\infotafeln_1': u'C:\\Scripts\\Redefine Projection\\MyGeodatabase.gdb\\FD_A_redefined', 
u'C:\\Scripts\\Redefine Projection\\MyGeodatabase.gdb\\FD_B\\sielhautproben_2': u'C:\\Scripts\\Redefine Projection\\MyGeodatabase.gdb\\FD_B_redefined', 
u'C:\\Scripts\\Redefine Projection\\MyGeodatabase.gdb\\FD_B\\infotafeln_2': u'C:\\Scripts\\Redefine Projection\\MyGeodatabase.gdb\\FD_B_redefined'
}

Anyone out there have any idea what I'm doing wrong here?  I've also tried feeding FeatureClassToFeatureClass the key's basename, to no avail.  Any feedback is greatly appreciated!

0 Kudos
10 Replies
FreddieGibson
Occasional Contributor III

I would think that the simplest way I could get your code to work is as follows. You'll see that I'm creating a Guid to give me a unique name for your new feature class.

import arcpy
from os import path
from uuid import uuid4


for k, v in FCFDdict.items():
    fcName = "{}_{}".format(*[path.basename(k), str(uuid4()).split("-")[0].upper()])
    arcpy.conversion.FeatureClassToFeatureClass(k, v, fcName)