* 2-way associations

Writing and using plugins for Version 5 and above.
Post Reply
User avatar
DavidNewton
Superstar
Posts: 457
Joined: 25 Mar 2014 11:46
Family Historian: V6

2-way associations

Post by DavidNewton » 20 Jul 2014 15:03

Associations within BMD and Census records are well-covered by ancestral sources but there are other uses for Associations. Generally an association is 2-way but because the two people are not 'married' entering shared information is not only impossible but often the relationship between them is not sufficiently symmetric to be described in a single word or phrase (such as spouse). Hence, as has been mentioned on these forums , to use associations you need to enter the association for both individuals, and me being fundamentally lazy this is a clear case for a simple plugin.

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
David
Attachments
Create a 2-way Association.fh_lua
(1.39 KiB) Downloaded 125 times

User avatar
Jane
Site Admin
Posts: 7991
Joined: 01 Nov 2002 15:00
Family Historian: V6.2
Location: Somerset, England
Contact:

Re: 2-way associations

Post by Jane » 20 Jul 2014 15:25

Looks fine, I think, if you have Auto Source citation on then your new entries will get sourced even though you are using a plugin.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."

User avatar
DavidNewton
Superstar
Posts: 457
Joined: 25 Mar 2014 11:46
Family Historian: V6

Re: 2-way associations

Post by DavidNewton » 20 Jul 2014 16:05

Jane

I have never made use of automatic source citation so this is a new departure for me. However, when I set automatic source citation and tried to run the plugin I got a message saying that the plugin couldn't be run while automatic source citation was enabled. However, it got me thinking about sources. I suspect in most cases the source if there was one would have to be linked to both sides of the association. On the other hand most of the associations I have are speculative dealing with suspected relationships for which the source record is not good enough to be sure. I do think, however, that using associations is a great research tool. Something that was not available in the software I used to use.

David

Post Reply