I decided try Supertool to fix some inaccuracy in my DB. I want separate my Residence events which have multiple citations. Each Residence event should have only 1 citation. And Residence date should be the same as citation date. Places for separate Residences should be the same as for common one.
I’ve already found all needed people, events and citations. But I need some help:
How create new events and attach citations inside by hande?
How detach citation from event by hande?
How detach event from person by hande?
[Gramps SuperTool script file]
version=1
[title]
check
[description]
[category]
People
[initial_statements]
count = 0
[statements]
for event in events:
if event.type != 'Residence':
continue
if len(event.citations)<2:
continue
for citation in event.citations:
personId = gramps_id
personHandle = handle
eventId = event.gramps_id
eventHandle = event.handle
citationId = citation.gramps_id
citationHandle = citation.handle
citationExactDate = citation.date
count = count + 1
print(count, ").", "Person:", personId, personHandle, "Event:", eventId, eventHandle, "Citation:", citationId, citationHandle, citationExactDate)
[filter]
[expressions]
[scope]
all
[unwind_lists]
True
[commit_changes]
False
[summary_only]
False
Here is the final working script which separates one Residence event to multiple according to citations attached.
[Gramps SuperTool script file]
version=1
[title]
Separate Residence
[description]
# This script processes all individuals in the database and splits Residence events with multiple citations
# into separate events, each linked to a single citation. This ensures that each Residence event only has
# one citation attached to it.
[category]
People
[initial_statements]
[statements]
# Loop through all people in the database
personId = gramps_id
personHandle = handle
personEventRefList = []
# Loop through all events associated with the person
for commonEvent in events:
# Only process Residence events
if commonEvent.type != 'Residence':
continue
# Skip events that do not have multiple citations
if len(commonEvent.citations) < 2:
continue
# Get common event details
commonEventId = commonEvent.gramps_id
commonEventHandle = commonEvent.handle
commonEventObj = commonEvent.obj
commonEventPlaceHandle = commonEventObj.get_place_handle()
# Loop through each citation in the common event
for citation in commonEvent.citations:
citationId = citation.gramps_id
citationHandle = citation.handle
citationObj = citation.obj
citationDateObject = citationObj.get_date_object()
# Create a new Residence event with the citation
newEvent = Event()
newEvent.set_date_object(citationDateObject)
newEvent.set_type("Residence")
newEventCitationList = newEvent.get_citation_list()
newEventCitationList.append(citationHandle)
newEvent.set_citation_list(newEventCitationList)
newEvent.set_place_handle(commonEventPlaceHandle)
# Add the new event to the database
db.add_event(newEvent, trans)
newEventRef = EventRef()
newEventRef.set_reference_handle(newEvent.handle)
newEventRef.set_role("Primary")
# Remove the citation from the common event
commonEventObj.remove_citation_references([citationHandle])
# Add the new event reference to the person's event list
personEventRefList.append(newEventRef)
person.set_event_ref_list(personEventRefList)
print(f"Person {personId} events updated successfully")
# Remove the original common event from the database
db.remove_event(commonEventHandle, trans)
[filter]
[expressions]
[scope]
all
[unwind_lists]
True
[commit_changes]
True
[summary_only]
False