Select to view content in your preferred language

Copy and Paste Selected Table Rows in Standalone File Geodatabase Table

17993
11
06-17-2011 08:00 AM
JanSlaats
New Contributor III
I need to copy and paste selected rows in a standalone table.  The table is stored in a File Geodatabase. 

Simply using COPY and PASTE from the standard toolbar is not available!

According to the ArcGIS 10 Help page on Copying and pasting records in a table:
"This method of copying and pasting records is only valid for attribute tables of layers. It will not work for tables that have no associated features."

Can anyone suggest a work around?  I don't see why this simple function does not exist for a standalone table?!

Thanks in advance
Tags (2)
11 Replies
TimothyHales
Esri Notable Contributor
You can make your selection and then right click on the right side of the table where the gray boxes are and choose copy selected.

Here is another thread related to this issue:
Copying columns of attribute tables
0 Kudos
JanSlaats
New Contributor III
Thanks Tim.

Yes, I know you can COPY the selected set or rows, but there is no PASTE function?!

I need to not only COPY the selected rows in my standalone table, but also PASTE the same
rows into the same table.

That does not seem possible!

Cheers.
0 Kudos
TimothyHales
Esri Notable Contributor
I got you.  You are right, that does not work for PASTE.  It looks like there are several ideas on the ArcGIS Ideas page related to this issue.

Paste a column from Excel into an Attribute table.
Excel like Attribute Table editing and selection
Ability to edit standalone tables in ArcMap just as easily as feature classes

Not sure is this is applicable to your situation, but you could export the selected records and then append them to the new table.
0 Kudos
JonWebb
New Contributor
Have you tried selecting the rows you want to export then use Data > Export? Then you can us the Merge toolbox to get the data into the second table. It's a bit clunky but all I can think of at the moment.
0 Kudos
JanSlaats
New Contributor III
Thanks to all who responded!

The cumbersome work-around that works is as follows:

  • Select Rows in the Standalone Table

  • Choose Export... from the Table Options Menu

  • Save the Selected Rows to a new temporary Standalone Table in the same FGDB

  • In ArcToolbox, choose Data Management Tools > General > Append to append the new temporary Standalone Table to the original Standalone Table  (Use the Schema Type: TEST in the Append tool to ensure Schemas remain identical)

  • Delete the temporary Standalone Table

  • Repeat above steps as needed for each "Copy and Paste" action


Although this works, it's obviously a workflow that is tedious and time consuming,
and a simple COPY and PASTE functions are needed for Standalone Tables in ArcGIS !


I'm not the only one who could use this function, as documented in the Ideas section, here:

http://ideas.arcgis.com/ideaView?id=0873000000088RZAAY
JamieKass
Occasional Contributor
Or you could use Python to automate the row creation. Although this method is a bit more complex for the unexperienced, this method is much faster until a 'paste' function is implemented in attribute tables. The example below copies all the field attributes of the row with "Name" = 'PACIFIC AUTO SALVAGE' from feature class 'fc' and inserts it as a new row into the table. The query parameter in SearchCursor can be modified to query for different rows, and the rest of the function can be run the same way. To use, simply paste the function below into the Python Window, press enter twice, then call it like in the example below.

def pasteRow(fc, query):
    dict = {}
    for row in arcpy.SearchCursor(fc,query):
        for x in [k.name for k in arcpy.ListFields(fc) if k.name not in ['OBJECTID','Shape']]:
            dict = row.getValue(x)

    irows = arcpy.InsertCursor(fc)
    row = irows.newRow()
    for x in dict:
        row.setValue(x,dict)
    irows.insertRow(row)


Calling the code would look like this:
pasteRow(fc,'"SITENAME"=\'PACIFIC AUTO SALVAGE\'')


The InsertCursor can be replaced with an UpdateCursor if you'd like to create a new feature and then copy all the attributes from a different row into the new one. If there is a need for this example, I'd be happy to post it.
0 Kudos
EvanThoms
Occasional Contributor II
Here's a way to automate Jan's workaround:

Open your table.
Open the python interpreter window
Type in this function

>>> def cRows(xTimes):
...     for i in range(0, xTimes):
...         arcpy.CopyRows_management("tblMyRecords", "tblScratch")
...         arcpy.Append_management("tblScratch","tblMyRecords")
... 


Select a row or the rows you need to copy one or more times and call the function in the python window like this

>>> cRows(6)
  

If you need X copies, give the function X - 1; you already have one copy in your table.

tblScratch should get written to your default gdb. If the function can't find it, try adding it to your layers.

It works inside and outside of an edit session.
0 Kudos
RichardFairhurst
MVP Honored Contributor
Here's a way to automate Jan's workaround:

Open your table.
Open the python interpreter window
Type in this function

>>> def cRows(xTimes):
...     for i in range(0, xTimes):
...         arcpy.CopyRows_management("tblMyRecords", "tblScratch")
...         arcpy.Append_management("tblScratch","tblMyRecords")
... 


Select a row or the rows you need to copy one or more times and call the function in the python window like this

>>> cRows(6)
  

If you need X copies, give the function X - 1; you already have one copy in your table.

tblScratch should get written to your default gdb. If the function can't find it, try adding it to your layers.

It works inside and outside of an edit session.


I just saw this workaround mentioned in your comments on the Ideas website.  To make it easier to copy/paste the function (which is in line with the point of this thread) I have removed the extraneous characters from your code blocks.  I have also made the function take an input table name, so that it is more flexible.  Also, CopyRows_management only needs to be run once, and the loop for implementing multiple copies should only apply to the number of times Append_management is run.

def cRows(tblMyRecords, xTimes):
    arcpy.CopyRows_management(tblMyRecords, "in_memory/tblScratch")
    for i in range(0, xTimes):
        arcpy.Append_management("in_memory/tblScratch", tblMyRecords)


The input line to run the function has been modified to supply the table name (which the user needs to change) and only append 1 copy of the selected rows to the table by default.  (cRows(0) did not work, which is what I thought you meant for me to do when you said that the input expectes X -1 number of copies).

cRows("tblMyRecords", 1)


Is there a way to stop the tblScratch output from being added to my map without disrupting that behavior for other tools?  I tried the in_memory workspace, but it actually appended the in_memory workspace table to my map.  Also, the Append result does not show up in the output table view if it is open while the tool is running.  The table has to be closed and reopened to refresh with the appended data.  Is there any workaround for that behavior?

With the Append NO_TEST option I am assuming I could adapt this code's inputs so that it copied rows from one StandAlone table and pasted them into another.  Have you experimented with that option at all?  Thanks.
0 Kudos
Bud
by
Notable Contributor

Hi Richard,

 

It's been a while since you posted your modified script. Where you able to solve any of your questions? Do you still use this script, or do you have a more polished version?

 

0 Kudos