What I would love but lack the skills for to make it happen:
Gramps families have a property/field for entering a numerical value for the amount of children the family has. Ideally I’d love for this to automatically update as children are added (as I progress with my research). However this does not seem to be included in Gramps 5.1.6.
However, I’m optimistic that SuperTool can do the next best thing; count the number of children for every family and then write the count to the family property. With something like that I’d just have to remember to run this every once in a while.
Regrettably, I’m not that well versed in Python. Is anyone able and willing to help me with this?
Is it a good idea to use it that way? I use the number of children if I have a source that says „this family had 6 children“. When I find six names of those children then I know that I can stop for searching more of them. What is the added value of your use case?
This may or may not be useful but here is a Supertool script that does what was requested. The ‘number of children’ property is actually an attribute (with a predefined attribute type). The script first removes the attribute if it already exists and then adds it. The number of children is easily ‘computed’ with the expression ‘len(children)’. This script should be run in the Families category. The scope is defined as ‘All objects’ but of course you can first experiment with one or a few families (use ‘Selected objects’).
[Gramps SuperTool script file]
version=1
[title]
set-number-of-children
[description]
[category]
Families
[initial_statements]
from gramps.gen.lib import Attribute, AttributeType
[statements]
# remove the 'Number of Children' attribute if it already exists
attributes = family.get_attribute_list()
new_attributes = [a for a in attributes if a.type != AttributeType.NUM_CHILD]
family.set_attribute_list(new_attributes)
# add the 'Number of Children' attribute
count = len(children)
attr = Attribute()
attr.set_type(AttributeType.NUM_CHILD)
attr.set_value(str(count))
family.add_attribute(attr)
[filter]
[expressions]
[scope]
all
[unwind_lists]
False
[commit_changes]
True
[summary_only]
False
There a GEDCOM tag for this. But it is not supported by Gramps.
Perhaps there should be an custom Attribute naming pattern used to store a GEDCOM fragment or tag value?
from the 5.5.1 specification page 44
COUNT_OF_CHILDREN:= {Size=1:3}
The known number of children of this individual from all marriages or, if subordinate to a family record, the reported number of children known to belong to this family, regardless of whether the associated children are represented in the corresponding structure. This is not necessarily the count of children listed in a family structure.
Thank you all very much for your help and thoughts!
I agree with @hartenthaler that his use of this particular attribute is, ultimately, better. It’s probably wise to keep manually entered / sourced child counts separate from the values counted by a script.
However, I’m not entirely sure how to approach this. I can edit @kku 's very useful (thank you!!) script so that AttributeType becomes “_CUSTOM” but I’m unsure how to name this custom attribute (once again, help is greatly appreciated).
@emyoulation I also appreciate you pointing out that there’s two ways to count this (FAM-NCHI and NCHI). Do I understand you correctly when I state that these attributes are not by default present in Gramps?
To use a CUSTOM attribute type you can just use any string as the type, e.g.
… new_attributes = [a for a in attributes if a.type != "Childcount"]
… attr.set_type("Childcount")
I strongly suggest becoming very meticulous with collecting Scripts. It is very easy to lose track of them.
My method is to create a placeholder ‘Gramps’ family of SuperTool script authors in my tree. In the script’s Description, it is useful to add a link to the forum discussion where the script was published. Then use SuperTool’s File → Save to Note and attach the Note to the author. (This is made easier with Kari’s { @kku} new experimental Recent items addon.)