Select to view content in your preferred language

copy_management associated_data in loop to rename only renames the first

1464
4
Jump to solution
01-29-2019 07:10 AM
DavidPersson
Emerging Contributor

Hi,

I'm using the ArcGIS Pro Python console (we are using ArcGIS Desktop 10.5 mostly but its copy_management doesn't have the associated_data parameter) in order to try to do the following:

Copy all feature classes under a specific data set in an enterprise geodatabase to a new / existing data set with a specific name in the same database and in the process rename the feature classes using a suffix.

This is the current python code:

suffix = "_imahappysuffix"


in_data =  "C:/tempo/pyth/data_owner_connection.sde/db_test.dataowner.mexico"

out_data = "C:/tempo/pyth/data_owner_connection.sde/db_test.dataowner.newdataset"


arcpy.env.workspace = r'C:\tempo\pyth\data_owner_connection.sde'


dss = arcpy.ListDatasets("db_test.dataowner.mexico","Feature")

for ds in dss:
    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
        arcpy.Copy_management(in_data, out_data, associated_data=fc+" FeatureClass "+fc+suffix)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This executes and creates a new dataset named newdataset (if it didn't exist) and then creates a copy of the first feature class with the intended suffix. The second and third feature classes in the origin data set however are only given a _1 suffix in the target data set, how come?

I think something might be wrong with how I use associated_data but I haven't figured out what yet.

In the target data set I'm getting:

db_test.dataowner.mexico_dots_imahappysuffix

db_test.dataowner.mexico_realms_1

db_test.dataowner.mexico_rivers_1

Thanks for reading : )

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

Copy Features—Data Management toolbox | ArcGIS Desktop if you are just copying featureclasses

Copy—Data Management toolbox | ArcGIS Desktop  has a lot more fluff associated with it and seems to be targeted for particular situations

Is it your intention to use the latter instead of the former?

View solution in original post

4 Replies
JoshuaBixby
MVP Esteemed Contributor

I haven't worked with the newish associated_data parameter yet, but according to Copy—Data Management toolbox | ArcGIS Desktop you appear to be running into some form of expected behavior:

The from_name and to_name column names will be identical if the to_name is not already used in out_data. If a name already exists in the out_data, a unique to_name will be created by appending an underscore plus a number, _2.

In your case it is appending _1 instead of _2

DavidPersson
Emerging Contributor

Thanks, that's a good point; possibly it's copying all origin feature classes thrice, hah, loop-logic-failure if so. Checking..

0 Kudos
DanPatterson_Retired
MVP Emeritus

Copy Features—Data Management toolbox | ArcGIS Desktop if you are just copying featureclasses

Copy—Data Management toolbox | ArcGIS Desktop  has a lot more fluff associated with it and seems to be targeted for particular situations

Is it your intention to use the latter instead of the former?

DavidPersson
Emerging Contributor

My intention is to get all feature classes in a specific data set copied under new names (suffix) into another dataset; seems Copy Features can do just that too, after CreateFeatureDataset. Got it working now with a .gdb-source and target, will try .sde-target tomorrow. Cheers for the advice!  : )

Edit. Just wanted to say that CopyFeatures_management appears to work for the intended job. No potential issues with selections either as enterprise geodatabase feature classes -> enterprise geodatabase feature classes. Thanks again! (if anyone is interested in the rough little script I made I'll attach it here, am not certain yet how the forum usually goes )

0 Kudos