Hello Everyone,
I have a point feature with a single field used as the the attribute key for relationship classes to other tables. I am looking to automatically create a row into the related tables with the key field populated from the point creation. Any ideas how to auto populate the tables with that key?
Below is a screenshot of the inside of database.
Thank you!
Paul McBride
Hello Paul,
I'm a little confused, do you want to copy the first row in your points file to a new row in each of the related tables?
Regards,
Josh
Thank for the reply.
Yes that is what I would like to do.
When a user places a new point I would like them to be able to edit the related tables immediately without having to create a new record for that point. The related tables would automatically receive the point ID field that relates them together.
Thanks again.
Ok, so I wrote a small python script that should work. The script should be able to handle a few points really quickly, but will be slower than needed if your very large numbers of input points. Since your said it will only be one at a time, this should be fine.
I included two ways of selected your related tables (manually and automatically). Remove the method you choose not to use. You will also need to make sure your key field already exists in all your related tables.
import arcview import arcpy workDir="C:\\path\\to\\data\\TESTGeodatabase.gdb" pointsFC="MCCOG_Complaint.DBO.complaint" keyField="complaintKey" #Manually select related tables: relatedTables=["MCCOG_Complaint.DBO.complaintProblem","MCCOG_Complaint.DBO.complaintWorkOrder","MCCOG_Complaint.DBO.complaintContractor"] #Automatically select related tables: arcpy.env.workspace=workDir relatedTables=arcpy.ListTables("MCCOG_Complaint.DBO.complaint*") #all table that begin with 'MCCOG_Complaint.DBO.complaint' #Copy rows to related tables: with arcpy.da.SearchCursor(workDir+"\\"+pointsFC,[keyField]) as inRows: for inRow in inRows: for relatedTable in relatedTables: with arcpy.da.InsertCursor(workDir+"\\"+relatedTable,[keyField]) as outRows: outRows.insertRow(inRow) print("Complete!")
Let me know how it goes!
Seems like you would want to create the search cursor on just the selected features instead of everything in the point feature class. I think the way you have it now would copy all rows in the point feature class to the related tables each time a new point was added (creating duplicate records in the related tables).
Josh,
Thank you for the script. Did you run this within arcmap or did you create an addin and then put code into python script?
Still invaluable 6 years later. Thanks Joshua
Hello Paul,
I actually ran my python script outside of ArcMap using IDLE, but it can also be run within ArcMap. I did not set it up as a python add-in. Also, as Blake pointed out, the script will copy over ALL keys in the complaint file to the related tables each time it runs (thanks for that catch Blake!).
I have a few ideas on how to proceed;
Let me know what you think!
Hey Josh,
Option 3 sounds great. What I would like to do is get this script into a button that after the point is placed and assigned the key number then they could hit the button and apply to the related tables.
Thanks again!!!!
Paul,
did you ever find a way to do this? I am trying to create the exact same thing with a button my end users could click to create the related records. Thanks for any pointers