For obscure reasons associated with conveying information in an FH GEDCOM imported into Ancestry.com, I want to provide each individual with a custom BACKGROUND event, with the information in a PLACe subfield. So I thought a plugin might do the job. But I'm struggling.
After much trial and error, the code below nearly works. It creates the appropriate GEDCOM statements:
[pre] 1 EVEN
2 TYPE Background
2 PLAC My text here[/pre]
for each individual. The problem is: it doesn't detect if an individual already has the requisite info; the lines always get created.
My current code is as follows. The commented-out pseudo-code represents the test that I think I need.
[pre]ptrIndi = fhNewItemPtr() -- Pointer to Individuals
ptrIndi:MoveToFirstRecord('INDI') -- First individual
iTotalCount = 0 -- Number of individuals
iModCount = 0 -- Number of modifications
strTag, strError = fhGetFactTag('Background', 'Event', 'INDI', true)
if strTag == '' then
fhMessageBox('Error: ' .. strError)
else
while not ptrIndi:IsNull() do -- For all individuals
iTotalCount = iTotalCount + 1
--> if (INDI doesn't have a Background event with a PLAC subfield)
ptrBg = fhCreateItem(strTag, ptrIndi) -- create a Background field within this record
ptrBgPlac = fhCreateItem('PLAC', ptrBg) -- create a Place subfield within this record
fhSetValueAsText(ptrBgPlac, 'My text here') -- set value of the field
iModCount = iModCount + 1
--> end
ptrIndi:MoveNext()
end
fhMessageBox('The project contains '..
iTotalCount..' individualsn'..
iModCount..' were modifiedn'
)
end[/pre]
Any help gratefully received.
Two observations before I go. The FH Plugin help seems very thin on coherent in-context examples once we get past the simplistic read-only examples; updating is given not nearly enough attention (at least, in the stuff that I've read). And I strongly support Mike Tate's remarks about the need to establish a naming style for variables -- across specification, hard-copy examples and live samples -- and then to stick to it religiously.
ID:5456
* Struggling with an 'update' plugin
- RogerF
- Famous
- Posts: 182
- Joined: 26 Apr 2009 16:32
- Family Historian: V6.2
- Location: Oxfordshire, England
- Contact:
Struggling with an 'update' plugin
Roger Firth, using FH to research the FIRTHs of Lancashire and Yorkshire, and the residents of the market town where I live.
- tatewise
- Megastar
- Posts: 27076
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Struggling with an 'update' plugin
You were pretty close Roger, but this seems to work on my database.
Code: Select all
ptrIndi = fhNewItemPtr() -- Pointer to Individuals
ptrIndi:MoveToFirstRecord('INDI') -- First individual
iTotalCount = 0 -- Number of individuals
iModCount = 0 -- Number of modifications
ptrEvent = fhNewItemPtr() -- Pointer to EVENt Tag
ptrPlace = fhNewItemPtr() -- Pointer to PLACe Tag
strEvent, strError = fhGetFactTag('Background', 'Event', 'INDI', true)
if strEvent == '' then
fhMessageBox('Error: ' .. strError)
else
while not ptrIndi:IsNull() do -- For all individuals
iTotalCount = iTotalCount + 1
ptrEvent:MoveTo(ptrIndi,'~.'..strEvent)
if ptrEvent:IsNull() then -- INDI doesn't have a Background Event
ptrEvent = fhCreateItem(strEvent, ptrIndi) -- create a Background Event field within this record
ptrPlace = fhCreateItem('PLAC', ptrEvent) -- create a Place subfield within this record
fhSetValueAsText(ptrPlace, 'My text here') -- set value of the field
iModCount = iModCount + 1
end
ptrIndi:MoveNext('SAME_TAG')
end
fhMessageBox('The project contains n'..
iTotalCount..' individualsn'..
iModCount..' were modifiedn'
)
end
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- RogerF
- Famous
- Posts: 182
- Joined: 26 Apr 2009 16:32
- Family Historian: V6.2
- Location: Oxfordshire, England
- Contact:
Struggling with an 'update' plugin
Thanks, Mike. Works a treat.
Roger Firth, using FH to research the FIRTHs of Lancashire and Yorkshire, and the residents of the market town where I live.