Select to view content in your preferred language

Copy and Paste Features between Feature Classes - VB.NET ArcGIS 10

5899
1
Jump to solution
04-17-2012 09:51 AM
ChanningDale
Occasional Contributor
Hello all,

I'm currently in the midst of upgrading a custom tool from 9.3.1 executable to 10.0 ESRI add-in, and I've come across two commands, esriArcMapUI.EditCopyCommand and esriArcMapUI.EditPasteCommand that aren't working properly.  An edit session is started through code, features are selected through a query and placed in a feature selection, and then the two command names get passed into the following method:

-----------------------

Public Shared Sub ExecuteCmdArcMap(ByVal strUID As String)
            'Description:      Executes the spcified ArcMap Command Button.
            'Input Parameters: 1) strUID(String) representing the specified ArcMap tool's UID.
            Dim pDoc As ESRI.ArcGIS.Framework.IDocument
            Dim pCmdBars As ESRI.ArcGIS.Framework.ICommandBars
            Dim pItem As ESRI.ArcGIS.Framework.ICommandItem
            Dim pUID As UID

            Try
                pUID = New UID
                pUID.Value = strUID
                pDoc = My.ArcMap.Document
                pCmdBars = pDoc.CommandBars
                pItem = pCmdBars.Find(pUID)
                pItem.Execute()
            Catch ex As Exception
                StatusLog.LogError(ex.ToString)
            End Try
        End Sub

--------------------------

The copy command is copying selected road centerline features from one feature class stored in an SDE database, and pasting them into an identical copy of the same feature class stored in either a file geodatabase or a personal geodatabase (a new database gets created at the beginning of the tool, and it is up to the user to select which database he or she wants to use).  When the code tries to execute these commands, I get the following error message: "No acceptable target available.  Target geometry type must match that of the feature(s) being pasted."  This doesn't make sense to me because the geometry of two feature classes is the same since they are both line feature classes.

I have a couple of hunches: 1) the copy and paste functionality has changed between 9.3.1 and 10, which is something that I've dealt with before in other upgrades but not quite in this manner.  From experience, when you manually copy a feature in the ArcMap UI and paste it, a dialog box comes up and prompts you to select a target layer to paste to.  I also tested the copy/paste manually between the two feature classes and it worked.  2) There may be differences between a feature class in an SDE database and one in a personal or file geodatabase.

Does anyone have any ideas on how to either replace these commands or make them work?

Thanks!

-Channing


Edit: I've also been experimenting with the editing template functionality and seeing if these need to be accessed for copying and pasting.
0 Kudos
1 Solution

Accepted Solutions
ChanningDale
Occasional Contributor
After much brainstorming and head-scratching, a solution was finally found on how to replace these commands.  There is another command in ArcMap called "Load Objects" that behaves almost the exact same way as the Simple Data Loader in ArcCatalog; the only difference is that after navigating to the location of the source feature class/table, the destination of the data is a layer chosen from the MXD.  The command also allows you to map fields for loading.

The interface I used is IObjectLoader.  Since the schema of the destination feature class that I'm loading the data into is an exact copy of the source feature class, I didn't have to worry about using field mapping objects in code.

Here's the examples I used in order to get the IObjectLoader.LoadObjects method working:

C# example

VBA example

The VBA example was pretty easy to change over to VB.NET and adapt to the variables I was already using in code.  This thread got a lot of views, so I hope it helps people who are also searching for a solution!

View solution in original post

0 Kudos
1 Reply
ChanningDale
Occasional Contributor
After much brainstorming and head-scratching, a solution was finally found on how to replace these commands.  There is another command in ArcMap called "Load Objects" that behaves almost the exact same way as the Simple Data Loader in ArcCatalog; the only difference is that after navigating to the location of the source feature class/table, the destination of the data is a layer chosen from the MXD.  The command also allows you to map fields for loading.

The interface I used is IObjectLoader.  Since the schema of the destination feature class that I'm loading the data into is an exact copy of the source feature class, I didn't have to worry about using field mapping objects in code.

Here's the examples I used in order to get the IObjectLoader.LoadObjects method working:

C# example

VBA example

The VBA example was pretty easy to change over to VB.NET and adapt to the variables I was already using in code.  This thread got a lot of views, so I hope it helps people who are also searching for a solution!
0 Kudos