Programatic add of Note and Citation to Association

Can someone tell me the correct way to programmatically add a Note and Citation to an existing Association.

Note, Citation, and PersonRef (Association of active_person) exist in db. I tried:

with DbTxn (‘Add Note Cit’, self.dbstate.db) as self.trans:
personRef.add_note(existing_note)
personRef.add_citation(existing_cit)
self.dbstate.db.commit_person(active_person, self.trans)

and it crashes in the commit_person.

Would the Isotammi Generate Citations addon tool give enough example code to reference?

(Warning! Be careful experimenting in the GUI. This tool changes the tree without a confirmation… despite the ellipsis indicating a dialog.)


Wiki:

Generate source citations from notes

The Generate source citations from notes tool is a specialized tool that can interpret a source reference obtained from a digital directory or SSHY page, which is stored in Gramps, eg for additional information about an event. The tool then forms the based on the text reference to the source, source, and archive Gramps and deletes the original additional information. The additional information must not contain other text and the source reference must be copied there as it is. The tool processes all additional information in this format at the same time. The SSHY source reference must be retrieved using a special SSHY browser extension (SSHY-selainlaajennus – Get this Extension for 🦊 Firefox (en-US) or https://chrome.google.com/webstore/detail/sshy-selainlaajennus/caomdaijfcdopklkecajpkoaiamaegkb )

No, that adds Citations to Primary Objects - straightforward. My challenge is adding them to a Reference Object.

1 Like

The add_citation and add_node calls take a handle as the parameter.

So something like this should work:


with DbTxn (‘Add Note Cit’, self.dbstate.db) as self.trans:
    personRef.add_note(existing_note.handle)
    personRef.add_citation(existing_cit.handle)
    self.dbstate.db.commit_person(active_person, self.trans)
2 Likes