-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAll Surnames.fh_lua
135 lines (126 loc) · 4.95 KB
/
All Surnames.fh_lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
--[[
@title: List All The Possible Names
@author: Calico Pie
@lastupdated: August 2010
@description:
Script reads through all individuals and lists all variations of Names from the Name field
and for married women lists them under their married names as well.
Note All family as Spouse occurrences will be listed even if there is no marriage recorded.
]]
function main()
pi = fhNewItemPtr() -- declare pointer
pi:MoveToFirstRecord('INDI') -- set the first to point to the first Note record
pi2 = fhNewItemPtr()
pfl = fhNewItemPtr()
pf = fhNewItemPtr()
count = 0
local tbl = createResultTable()
-- Define Columns
tbl.surname = {title="Surname",type="text",width=60,sort=1}
tbl.given = {title="Given Names", type="text", width=80,sort=2}
tbl.type = {title="Lifedates", type="text", width=40}
tbl.lifedates = {title="Lifedates", type="text", width=40}
tbl.marriage = {title="Marriage", type="text",width=80}
tbl.record = {title="Record",width=160}
tbl.familyrecord = {title="Family Record",width=160}
local tblTypes = {'Primary','Secondary','Married'}
while not pi:IsNull() do
-- Do Work Here
if not pi:IsNull() then
-- Get All Names from Name Fields
pi2:MoveTo(pi,"~.NAME") -- Get the Name for the INDI Record.
index = 1
while not pi2:IsNull() do
count = count + 1
tbl.surname[count] = fhGetItemText(pi2,'~:SURNAME')
tbl.given[count] = fhGetItemText(pi2,'~:GIVEN_ALL')
tbl.record[count] = pi:Clone()
tbl.lifedates[count] = fhCallBuiltInFunction('Lifedates',pi)
if index == 1 then
tbl.type[count] = tblTypes[1]
else
tbl.type[count] = tblTypes[2]
end
index = index + 1
pi2:MoveNext("SAME_TAG") -- next Name
end
-- Look For Married Names
strSex = fhGetItemText(pi,'INDI.SEX')
if (strSex == 'Female') then
pfl:MoveTo(pi,"~.FAMS")
while not pfl:IsNull() do
pf = fhGetValueAsLink(pfl)
count = count + 1
tbl.surname[count] = fhGetItemText(pf,'FAM.HUSB>NAME:SURNAME')
tbl.given[count] = fhGetItemText(pi,'INDI.NAME:GIVEN_ALL')
tbl.record[count] = pi:Clone()
tbl.familyrecord[count] = pf:Clone()
tbl.lifedates[count] = fhCallBuiltInFunction('Lifedates',pi)
tbl.marriagedate[count] = fhGetItemText(pf,'FAM.MARR.DATE')
tbl.type[count] = tblTypes[3]
pfl:MoveNext("SAME_TAG") -- next Family as spouse
end
end
end
pi:MoveNext() -- next individual record
end
fhOutputResultSetTitles("List All Individuals under All Possible Names",
"List All Individuals under All Possible Names",
"Printed: %#x")
fhOutputResultSetColumn("Surname", "text", tblSurname, #tblSurname, 60, "align_left", 1, true)
fhOutputResultSetColumn("Given Names", "text", tblGivenAll, #tblSurname, 80, "align_left", 2, true)
fhOutputResultSetColumn("Type", "text", tblNameType, #tblSurname, 40, "align_left", 3, true)
fhOutputResultSetColumn("Lifedates", "text", tblLifeDates, #tblSurname, 40, "align_left")
fhOutputResultSetColumn("Marriage", "text", tblMarriageDate, #tblSurname, 80, "align_left")
fhOutputResultSetColumn("Record", "item", tblRecord, #tblSurname, 160, "align_left")
fhOutputResultSetColumn("Family", "item", tblFamilyRecord, #tblSurname, 160, "align_left")
end
function createResultTable()
local tblOutput_mt = {} -- create metatable
local iC = 0 -- Define count of lines
local tblOutput = {} -- Define Columns Table
tblOutput_mt.col = 0
tblOutput_mt.seq = {}
tblOutput_mt.__index = self
tblOutput_mt.__newindex =
function (t,k,v)
-- Set Values to Defaults if not supplied
if v.content == nil then v.content = {} end
if v.title == nil then v.title = k end
if v.type == nil then v.type = 'item' end
if v.width == nil then v.width = 140 end
if v.align == nil then v.align = 'align_left' end
v.set =
function(self,value)
self.content[iC] = value
end
rawset(t,k,v) -- update original table
local m = getmetatable(t)
m.col = m.col + 1
table.insert(m.seq,k)
end
tblOutput_mt.__call =
function (t)
local i = 0
local m = getmetatable(t)
local n = table.getn(m.seq)
return function ()
i = i + 1
if i <= n then
return t[m.seq[i]]
end
end
end
function tblOutput:newRow()
iC = iC + 1
end
function tblOutput:outputResults()
for l in self() do
fhOutputResultSetColumn(l.title, l.type, l.content, iC, l.width,l.align)
end
end
setmetatable(tblOutput, tblOutput_mt)
return tblOutput
end
------------------------------------------------------------------------- Run Main
main()