Loop All Facts for an Individual (code snippet)

Description

Iterates all Facts for an Individual. Takes a pointer as a parameter.

Requires: None

Code

LoopAllFacts.fh_lua
function facts(pi)
    local pf = fhNewItemPtr()
    local pf2 = fhNewItemPtr()
    pf:MoveToFirstChildItem(pi)
    return function ()
        while  pf:IsNotNull() do
            pf2:MoveTo(pf)
            pf:MoveNext()
            if fhIsFact(pf2) then return pf2 end
        end
    end
end

Usage

i = 0
pi = fhNewItemPtr()
pi:MoveToFirstRecord('INDI') -- Move to first individual record
 
for px in facts(pi) do
    print (fhGetDisplayText(px))
    i = i + 1
end
print(i)