Struggling with an 'update' plugin
Posted: 11 Sep 2011 20:14
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
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