TheGeneGenieProject / GeneGenie.Gedcom

A .Net library for loading, saving, working with and analysing family trees stored in the GEDCOM format.
GNU Affero General Public License v3.0
52 stars 23 forks source link

How can I extract a subtree from a Gedcom file? #136

Open viniciostorres opened 9 months ago

viniciostorres commented 9 months ago

Tanks for excelent c# library for Gedcom. I think this is the best library I found to this.

I have a Gedcom file exported from MyHeritage that have hundreds of Individuals and Families. I want to export only a specific family to a new Gedcom file. I open the original file and select the individuals I need and added to new database.

But when I write a new Gedcom using GedcomRecordWriter.OutputGedcom(exportGedcom, "Rewritten.ged"); I get the error:

Exception has occurred: CLR/System.NullReferenceException
An unhandled exception of type 'System.NullReferenceException' occurred in GeneGenie.Gedcom.dll: 'Object reference not set to an instance of an object.'
   at GeneGenie.Gedcom.Parser.GedcomRecordWriter.Write(GedcomDatabase database, GedcomStreamWriter writer) in /home/vinicios/workspace/GeneGenie.Gedcom/GeneGenie.Gedcom/Parser/GedcomRecordWriter.cs:line 161

What I need to do to build a valid new Gedcom using informations from another Gedcom file?

Thanks again,

Vinicios Torres

RyanONeill1970 commented 9 months ago

I'll have to look into it, would you be able to share the data file that caused the error? You could email it to me if needed (r@genegenie.com).

viniciostorres commented 9 months ago

HI, Ryan,

I have found some issues, I think. First, it is not enough to create new GedcomDatabase using:

var exportGedcom = new GedcomDatabase();

It have generated null exception because the abscence of Header. So, to solve that I created a gedcom file with just header to be a base of new database.

And I discovered that I must use:

exportGedcom.Add( individual.XRefID, individual);

to add an imported person (and events, photos, families) to new database. Initially I thought I should use exportGedcom.Individuals.Add(individual);

I will continue testing here and then report back to you my experience with the library.

Tahks.