Woody
August 16, 2026, 10:07am
1
Hi,
I’m currently creating a family history book based on a village. I’ve already merged several individuals.
As a result, I naturally have many duplicate entries in the events section. I’d like to somehow consolidate these. Here’s an example:
The profession “Master Baker” appears three times, each with a different date.
Kari @kku , could this be combined using a Supertool script?
So, if the type, description, and location of the event are the same, and only the date and source differ, the date should, of course, be expanded to a range (from-to), and the source should be added to the others.
Could you please help me with a script again?
OS: Win 64, Gramps AIO64-6.0.8–1
Thank you in advance.
Woody
August 16, 2026, 10:28am
2
Here is another extreme example.
kku
August 16, 2026, 1:08pm
3
I can try to make such a script.
In the meantime you may take a look at the README.md before installing this addon: gramps/addons/events_and_citations at master · kkujansuu/gramps · GitHub
With it you can manually merge a person’s events by dragging them in the gramplet window (e.g. in bottombar). It also supports merging date ranges.
But if you have a large number of such people then a script would be more suitable.
Woody
August 16, 2026, 2:11pm
4
Hi Kari,
I wasn’t familiar with this Gramplet.I never stop learning with Gramps.
But there are mutch more than 1000 people. That’s why I’m asking if Supertool can handle that. I would have processed 100 people manually or with the Gramplet you just discovered.
kku
August 16, 2026, 5:00pm
5
Try this script. The file merge-events.py is in the next message.
merge-events.script:
[Gramps SuperTool script file]
version=1
[title]
merge-events
[description]
[category]
People
[initial_statements]
@include merge-events.py
[statements]
process_person(self)
[filter]
[expressions]
[scope]
selected
[unwind_lists]
False
[commit_changes]
False
[summary_only]
True
kku
August 16, 2026, 5:01pm
6
merge-events.py
def process_person(p):
eventmap = defaultdict(list)
for e in p.events:
key = (e.type, e.description, e.place.longname)
eventmap[key].append(e)
for key, eventlist in eventmap.items():
if len(eventlist) > 1:
merge_all(eventlist)
def merge_all(eventlist):
if len(eventlist) > 1:
e1 = eventlist[0]
e2 = eventlist[1]
mergeevents(e2.obj, e1.obj)
merge_all(eventlist[1:])
def mergeevents(e1, e2):
import gramps.gen.merge.mergeeventquery as mergemodule
date1 = e1.get_date_object()
date2 = e2.get_date_object()
newdate = merge_date_ranges(date1, date2)
e1.set_date_object(newdate)
saved_txn = mergemodule.DbTxn
try:
mergemodule.DbTxn = DummyTxn(trans).txn
query = mergemodule.MergeEventQuery(dbstate, e1, e2)
query.execute()
finally:
mergemodule.DbTxn = saved_txn
e2.commit_ok = False
def merge_date_ranges(date1, date2):
if date1.get_ymd() == (0, 0, 0): return date2
if date2.get_ymd() == (0, 0, 0): return date1
low1 = date1.get_ymd()
low2 = date2.get_ymd()
hi1 = date1.get_stop_ymd()
hi2 = date2.get_stop_ymd()
if hi1 == (0,0,0): hi1 = low1
if hi2 == (0,0,0): hi2 = low2
newlow = min(low1, low2)
newhi = max(hi1, hi2)
newdate = Date()
newdate.set(modifier=Date.MOD_SPAN, value=[newlow[2], newlow[1], newlow[0], False, newhi[2], newhi[1], newhi[0], False])
return newdate