The script below is a first attempt and no doubt could be massively improved. However, it does work. I have made no effort as yet to add sources, or notes, because once the association is set up that is straightforward from the property box
Code: Select all
--[[
@Title: Create a 2-way Association
@Author: David Newton
@Version: 0.0
@LastUpdated:
@Description: Applies to two individuals
]]
pi1=fhNewItemPtr()
pi2=fhNewItemPtr()
pi1c=fhNewItemPtr()
pi2c=fhNewItemPtr()
pi1cr=fhNewItemPtr()
pi2cr=fhNewItemPtr()
require("iuplua")
while pi1:IsNull() do
tRec=fhPromptUserForRecordSel('INDI',2) -- check that two records have been selected
if #tRec ~= 2 then
button=fhMessageBox('You need to select precisely two individuals','MB_OKCANCEL')
if button=='Cancel' then break end
else
pi1=tRec[1] pi2=tRec[2]
end
end
if pi1:IsNotNull() then
pi1c=fhCreateItem('ASSO',pi1,true)
fhSetValueAsLink(pi1c,pi2)
pi2c=fhCreateItem('ASSO',pi2,true)
fhSetValueAsLink(pi2c,pi1)
pi1cr:MoveTo(pi1c,'~.RELA')
pi2cr:MoveTo(pi2c,'~.RELA')
res,relat12, relat21=iup.GetParam("Relationships",nil,"Relationship of "..fhGetDisplayText(pi2).." to "..fhGetDisplayText(pi1)..": %s\n".."Relationship of "..fhGetDisplayText(pi1).." to "..fhGetDisplayText(pi2)..": %s\n","","")
fhSetValueAsText(pi1cr,relat12)
fhSetValueAsText(pi2cr,relat21)
tAssoc={relat12,relat21}
tRev={pi2,pi1}
fhOutputResultSetColumn('Associate','item',tRev,2,120)
fhOutputResultSetColumn('Relationship to','text',tAssoc,2,120)
fhOutputResultSetColumn('Name','item',tRec,2,120)
end