Need help in writing arcpy script where i have same feature class names

468
6
12-03-2021 01:06 PM
SaM1
by
New Contributor II

Hi,

I need to write a script that deletes rows from one feature class and append data from another feature class to the first feature class. Both feature class has the same name but are stored in a different location, I need to run this script in the python window, I was wondering what could be the workaround to accomplish this task. The script needs to run in a Python window and other users need to run the script as well.  

Here is an example below:

Feature Class A = Need to delete rows from this feature class. 

Feature Class A = Append data from this feature class to the first feature class.

 

I hope this makes sense

 

Thanks,

SAM!

Tags (1)
0 Kudos
6 Replies
SaM1
by
New Contributor II

Thank you, These links are helpful!

 

SAM!

0 Kudos
JohannesLindner
MVP Frequent Contributor

And regarding the same names: Use the full paths.

 

original_fc = "path:/to/the/fc_to_be_updated/FC_A"
update_fc = "path:/to/the/update_fc/FC_A"

arcpy.management.TruncateTable(original_fc) # deletes ALL rows!
arcpy.management.Append(original_fc, update_fc) # for same table schema

 

 


Have a great day!
Johannes
SaM1
by
New Contributor II

Thank you, Johannes! this is working for me, but just a quick question, if I want to share this script with my colleague, how they are going to run it as I have assigned a path to my directories. I am just a beginner and still learning concepts of Python,

Again Thank you for your help!

SAM

0 Kudos
JohannesLindner
MVP Frequent Contributor

If you are dealing with File Geodatabases (.gdb), they have to be in a location that is accessible to your colleagues.

If you're dealing with Enterprise Geodatabases (.sde), your colleagues have to connect as data owner to use TruncateTable. If they use their own connection files, they have to update the script with the right paths.

To run the script, your colleagues need ArcGIS installed on their PCs.

 

To share the script, you have a few options:

  • Just save it in a text file. To run it, copy paste into the ArcGIS Pro Python Window.
  • Insert "import arcpy" at the start of the script and save it as a python script (.py). Now you can also run it outside of ArcGIS, either using the command line or by opening it with IDLE (automatically installed with ArcGIS) and running it there.
  • Create a toolbox, turn the script into a script tool inside that toolbox, share the toolbox. Might be a bit overkill...
    https://pro.arcgis.com/de/pro-app/latest/arcpy/geoprocessing_and_python/a-quick-tour-of-creating-scr... 

Have a great day!
Johannes
0 Kudos
SaM1
by
New Contributor II

Thanks, Johannes, I am using the SDE version and I want to create a script tool, and in tool parameters, i will let users to input the data location paths.  I am not sure how to give a path to sde version in parameters. the tutorials i found are all related to creating a new version could not find anything related to using the existing sde version in arcpy.  One option I know is to go to the sde database connection properties and select geodatabase connection properties will allow you to change the whole sde connection database to the sde version, not sure if i should do that. Any advice from you would be greatly appreciated! and also i wanted to make that tool work for my colleagues too.

 

Thank you!

SAM1

0 Kudos