How to create a copy of the feature class

1316
3
Jump to solution
09-05-2019 08:44 AM
SusanFarley
New Contributor III

I have a project and am trying to create a copy of one or more layers in the project with all attributes. I remember someone saying the easiest way to see the syntax for how to do something was to execute it in arcpro and the look at the outputted code. How do you do that? I can't seem to fine that post.

I'm guessing the syntax for the copy will be along the lines of Geoprocessing.ExecuteToolAsync("management.CopyFeatureClass", <not sure of params>) but using the ExecuteToolAsync seems to take a while whereas Copy and Paste within ArcPro is very quick so I'm assuming there is faster syntax than this and I can't find it.

Thank you,

Susan

0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi Susan

You could use the LayerFactory's CopyLayer method.

var lyrToCopy = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
            await QueuedTask.Run(
                () => {
                    if (LayerFactory.Instance.CanCopyLayer(lyrToCopy))
                       LayerFactory.Instance.CopyLayer(lyrToCopy, MapView.Active.Map);
});

Thanks

Uma

View solution in original post

3 Replies
UmaHarano
Esri Regular Contributor

Hi Susan

You could use the LayerFactory's CopyLayer method.

var lyrToCopy = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
            await QueuedTask.Run(
                () => {
                    if (LayerFactory.Instance.CanCopyLayer(lyrToCopy))
                       LayerFactory.Instance.CopyLayer(lyrToCopy, MapView.Active.Map);
});

Thanks

Uma

SusanFarley
New Contributor III

That worked great! Thank you. How do I delete two fields from the new layer? I know which fields I want to delete, but was curious what the best way to do so programmatically would be.

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Susan,

In your new layer, to remove fields from the underlying feature class in the geodatabase, you have to use the Delete Field geoprocessing tool.

Thank you!

Uma

0 Kudos