* Adding 'avatars' to individuals

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Adding 'avatars' to individuals

Post by DavidNewton » 05 Nov 2016 12:23

I do not use diagrams, I just can't seem to navigate them properly, so I don't have access to all the decorative options. As a small step I add avatars to the individuals in my tree which give a very rough classification of status: male or female, with spouse or without, directly related or indirectly related or even not related at all. I also mark brick walls, spouses of relatives as roots of side tree and a special avatar for all direct line ancestors independent of gender. Of course these avatars can change as I add information to the tree so a plug-in is necessary to make the changing easy.

I am attaching the plugin in case anyone would find it useful and an image of the 13 avatars that I use, but you should choose your own. Should you decide to try this out be aware that you must manually add the media record numbers of the avatars, they are in a table av, but this is a one-off task.

David
Avatars.JPG
Avatars.JPG (17.63 KiB) Viewed 12051 times
Attach Avatars.fh_lua
(4.47 KiB) Downloaded 255 times

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 05 Nov 2016 13:16

Neat idea David.
Upon a very quick inspection, a few suggestions are worth mentioning:
  • Delete  before first --[[ so it will run in FH V5.
  • If the Avatar Media records were allocated predefined Titles (or Custom Id) then the av table could be automatically populated from a search of the Media (OBJE) records.
  • The trailing Err='Complete' must be removed, otherwise the other error messages never appear!
  • Make use of local variables to avoid risking clashes with global variables.
  • Assign fhCallBuiltInFunction('Relationship',proot,pi) to a variable to avoid calling multiple times, which on a large database may be rather slow. e.g.

    Code: Select all

    		a=av[8]	
    	else
    		local rel=fhCallBuiltInFunction('Relationship',proot,pi)
    		if rel=='' then
    			...
    		else
    			if string.find(rel,'wife') or string.find(rel,'husband') then
    				...
    			end
    		end
    	end
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 05 Nov 2016 14:21

Mike thank you for the comments. I'm not sure where the odd text  is as I cannot see it in my copy in FH.

I agree about the avatar media records, it would be nice if they were automatically picked up and I tried various ways of doing it but in the end I decided for me it was simpler to add the record numbers by hand. I take your points about repeated calls to a built-in function and my failure to use local variables. The Err message shouldn't have been there. I had in fact moved it but failed to remove it from the original incorrect position.

I will have another look at this and see if I can tidy it up a bit.

David

User avatar
PeterR
Megastar
Posts: 1129
Joined: 10 Jul 2006 16:55
Family Historian: V7
Location: Northumberland, UK

Re: Adding 'avatars' to individuals

Post by PeterR » 05 Nov 2016 14:28

From Wikipedia:
The UTF-8 representation of the BOM is the byte sequence 0xEF,0xBB,0xBF. A text editor or web browser misinterpreting the text as ISO-8859-1 or CP1252 will display the characters  for this. The Unicode Standard permits the BOM in UTF-8, but does not require or recommend its use.
Peter Richmond (researching Richmond, Bulman, Martin, Driscoll, Baxter, Hall, Dales, Tyrer)

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 05 Nov 2016 14:34

The  i text is inserted by default in V6 but can be removed by using the File > Coding option of ANSI instead of UTF-8 in the Plugin editor.

You search the Media OBJE records in the same way you search the Individual INDI records.
Create a table of Titles in the same order as your av table of Record Id.
In each record examine the OBJE.TITL field and use string.find(...) to search for matching Titles.
Loop through that Titles table until a match is found, then use the index to populate av table with Record Id.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 05 Nov 2016 16:02

I have been trying to make this run more efficiently by doing the calculations of gender etc as I need them and in doing so I realised that I had the priority order of avatars wrong. So I am going to rewrite that section.

For the moment I am going to leave the media records as they are since that will involve a rewrite of the plugin and also modification of all the relevant media records. Of course I could do that using this plugin and then rewrite the plugin.. ;)

One thing popped up which I have sort of solved but on which I would welcome some input. Because I used the shortcut ~SPOU[1] individuals who had children prior to marriage where tagged as unmarried even though they did get married. My first thought was to use ~SPOU[last] and then realised that I had at least one widow in my tree who carried on having children long after her husband died and so again was tagged as unmarried. Using ~SPOU[<2] works for my tree but it is not hard to see that it might not always work. Is there a better way?

David

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 05 Nov 2016 17:34

Sorry David but the more testing I do the more issues I discover.

InsertAvatar() function problems:

string.find(list,tostring(trec)) gives wrong value if trec is contained within any Rec Id in list.
e.g. If the trec is any single digit, then it will be found, even though it is not an avatar Rec Id.
So use:
string.find(list,":"..tostring(trec)..":") and ensure list encloses every Rec Id in colons.
There is another neater technique that is more efficient ~ remind me to tell you about it later.

if ext==false then simply does not work correctly.
So use:
if not ext then

The Media Title search is as follows where each av index is the Title of an Avatar Media record:

Code: Select all

local av={}
av["Avatar Brick Wall"]=0
av["Avatar Unspecified Gender"]=0
av["Avatar Direct Line Ancestor"]=0
av["Avatar Outside Relationship Pool"]=0
av["Avatar Male In-law Without Spouse"]=0
av["Avatar Male In-law With a Spouse"]=0
av["Avatar Female In-law Without Spouse"]=0
av["Avatar Female In-law With a Spouse"]=0
av["Avatar Spouses of Relatives"]=0
av["Avatar Male Relative Without Spouse"]=0
av["Avatar Male Relative With a Spouse"]=0
av["Avatar Female Relative Without Spouse"]=0
av["Avatar Female Relative With a Spouse"]=0
list = ":"
pi:MoveToFirstRecord('OBJE')
while pi:IsNotNull() do
	local title = fhGetDisplayText(pi)
	for avatar, recid in pairs (av) do
		if string.find(title,avatar) then
			av[avatar] = fhGetRecordId(pi)
			list = list..av[avatar]..":"
			break
		end
	end
	pi:MoveNext()
end
Then in the Individual record loop replace each a=av[9] with a=av["Avatar Brick Wall"], etc, that is much more meaningful.
Before that initialise a=0 and later test if a==0 then to report failure to classify.

I do not understand your question about ~SPOU[1] because that has nothing to do with Marriage.
A ~SPOU[1] is simply a partner in a Family record liaison. No Marriage Event need exist.
Conversely, any Individual may have ~CHIL[1] without a ~SPOU[1].
In plain language, what criteria are you trying to detect?
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 05 Nov 2016 20:19

I will have a closer look at this tomorrow. You are right about the trec matching, I have made this error in the past and I have resolved it (in the past) by making sure all the strings are the same length - padding them out with zeroes at the front.

The problem I was trying to resolve with the spouse was that I wanted the avatar to have a '+' sign if the individual had a spouse in any family record. Sorry to have regressed to using the incorrect terminology of marriage.

David

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 05 Nov 2016 22:15

The trick with things like trec matching is to create a table whose indexes are significant trec values set to true.
e.g. list={} and list[recid]=true so you can use if not list[trec] then in the InsertAvatar(...) function.
Thus the code within the Media OBJE search loop becomes:

Code: Select all

		if string.find(title,avatar) then
			local recid = fhGetRecordId(pi)
			av[avatar] = recid
			list[recid] = true
			break
		end
That avoids any padding and is much more efficient than string.find(...) searches.
The table index values can be anything such as numbers or text strings.
You will come to realise that tables are a most powerful Lua feature.

Regarding the ~SPOU[1]> shortcut, my interpretation is that it should return the first Spouse in any Family record, in the same way that the ~CHIL[1]> shortcut returns the first Child in any Family record. BUT it does NOT, which may be a bug!!!

The workaround is to use:
s=fhGetItemText(pi,'~.~SPOU[1]>')..fhGetItemText(pi,'~.~SPOU[2]>')..fhGetItemText(pi,'~.~SPOU[3]>')
that determines if a Spouse exists in one or more of the first three Family records, which should be enough.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 06 Nov 2016 09:01

Hi Mike

Not being that familiar with the ~SPOU shortcut I had looked it up in the help file. In the context of a family record it returns the first spouse in the family. In the context of an individual it returns the spouse of the individual (if there is one) in their first spouse family record. The indexed ~SPOU[<3] checks for a spouse going through the indexes 3,2,1 until it finds one. As you say that would normally be enough.

Regarding the automatic filling in of record id's the annoying thing is that I had all the ingredients in place and did not think to use them.

However, reading the plugin again I realise that a major issue here is that I was using string.find incorrectly. I had it in my head, and don't ask me why, that string.find returned a boolean value of true if it found the substring and false if it didn't. I am now going to rewrite the InsertAvatar function. Since the media records of the avatars have to have specific titles to allow the automatic entering of record numbers I am going to look at the possibility of having a specific, and unique to them, marker in the title, e.g, '** A Brick Wall' '** Unknown Gender' etc and then in the InsertAvatar function I will just need to search for the '** ' instead of checking record Ids.

When I have finished I will post the plugin again.

David

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 06 Nov 2016 10:20

David, I would strongly advise against doing the Avatar Media search in the InsertAvatar(...) function, because that will get repeated for every Individual, so with a large set of Media records that may take a very long time.

There is nothing fundamentally wrong with using string.find(), because it returns text or nil, which is equivalent to true or false. The fundamental point is that a Rec Id such as 23 will be found in the middle of a list such as :4567:1234:9876: whereas you only want those 4-digit Rec Id to be found. The list table is the efficient solution to such searches.

As I suggested, perform the Avatar Media search once at the start of the Plugin, and use two tables translating Rec Id:
1) av translating Media Title to Rec Id
2) list holding each Rec Id with value true
BTW: It may not be obvious, but you can actually use one table for both translations, because one uses only text indexes and the other uses only numeric indexes, so they are completely distinct.

Did you follow my logic of the ~SPOU[1]> shortcut versus the ~CHIL[1]> shortcut?
The Help for Understanding Data References says "The Spouse, Child and Witnessed event shortcuts allow you to do things you couldn’t otherwise do." and gives the example of %INDI.~CHIL[2]% that "will return a given person’s 2nd child by any marriage." (They don't actually mean marriage; they mean family record.)
So by analagy %INDI.~SPOUL[1]% should return a given person’s 1st spouse via any family record.
The %INDI.~SHAR>% shortcut similarly searches through all Individual/Family records.
Therefore, I think %INDI.~SPOUL[1]% is not implemented correctly.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 06 Nov 2016 11:20

Hi Mike

I have been working on the plugin this morning so have only just read your last post. I am attaching the version that I now have, which seems to work OK, but who knows?

David

I have detached the plugin as there was an error, see later post.
Last edited by DavidNewton on 06 Nov 2016 12:23, edited 1 time in total.

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 06 Nov 2016 11:42

Mike

I understand what you are saying about the ~SPOU shortcut and there is an ambiguity in the help file. I interpreted it that in the case of an individual this index would point to the spouse family number. In the Individuals record list I usually have the two columns for ~SPOU[1] and ~SPOU[2] and I have a number of individuals on file with, according to the index, a second spouse and with no first spouse. I don't consider myself sufficiently expert to say whether this implementation is right or wrong but I do think it is what FH does.

You will see that in my revisited plugin I don't use record numbers at all. I thought that the careful naming of the avatars would make it possible not to use them.

David

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 06 Nov 2016 12:22

There was an error in the revisited plugin in the order of pointers in the IsAncestorOf function call. I'm posting a corrected version.

David
Attach Avatars Revisited.fh_lua
(4.66 KiB) Downloaded 233 times

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 06 Nov 2016 12:47

OK David, that is looking quite good, and the technique for avoiding Rec Id by using Rec Pointers is a good one.

A minor loophole with Media Title is if the user happens to use '** .... (Avatar)' then that will be ignored and the icon Avatar will get used. In fact for it to work correctly, no other Media Title must start with '** ' except the icon Avatars.

A slight annoyance is that the process of deleting all the Media links and then recreating them, not only sets the Individual record Updated timestamp, but also each of the Media record Updated timestamps, even if the end result is that none of the Media actually change. So ideally the Plugin should compare existing Media with required Media and do nothing if they are the same.

As I said yesterday, your use of fhGetItemText(pi,'~.~SPOU[<2]>') is unsatisfactory.
I believe the objective is to return an empty string when the Indiviudal has no partner/spouse in any Family, and return a text string if there is a partner/spouse in at least one Family.
In your code, if there is a partner/spouse in the 1st Family or the 3rd Family but not in the 2nd Family, then it still returns an empty string saying there is NO partner/spouse when there is.
i.e. the most common case of a single Family with a Spouse it returns the wrong value!!!
You need to use:
fhGetItemText(pi,'~.~SPOU[1]>')..fhGetItemText(pi,'~.~SPOU[2]>')..fhGetItemText(pi,'~.~SPOU[3]>')
and hope that nobody has three initial Family liaisons without a partner recorded.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 06 Nov 2016 13:26

As I said yesterday, your use of fhGetItemText(pi,'~.~SPOU[<2]>') is unsatisfactory.
I believe the objective is to return an empty string when the Indiviudal has no partner/spouse in any Family, and return a text string if there is a partner/spouse in at least one Family.
In your code, if there is a partner/spouse in the 1st Family or the 3rd Family but not in the 2nd Family, then it still returns an empty string saying there is NO partner/spouse when there is.
i.e. the most common case of a single Family with a Spouse it returns the wrong value!!!
That is not the case. The <2 checks the second family and if no spouse then the first family. It does not return the wrong value in the most common case. Admittedly it may not be enough to just check two families but I assume (without checking it) that the index could be increased without problem.

I will look again at the wholesale deletion, The aim is to ensure that the 'new' avatar becomes the preferred avatar unless there already is a preferred avatar and to not attach multiple copies of the same avatar. Also as the file changes the avatar may change, for example if I find a spouse that I did not have before, Perhaps checking to see if the first media record is the same as the new avatar would curtail the whole proceeding without triggering changes in the Last Change date.

Regarding the ** checking, You are right , this beginning has to be unique to these avatars. Perhaps I also need to check that the media title I am checking is at least 3 characters long.

David

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 06 Nov 2016 14:30

Sorry, I misread ~SPOU[<2] as ~SPOU[2] but it is still far from foolproof.

If a person has a 1st Family Spouse and then a 2nd Family liaison without a partner, then it returns the empty string for the 2nd Family despite having a Spouse in the 1st Family.

If you extend it to ~SPOU[<3] then the same problem bedevils a 3rd Family liaison without a partner, or no 3rd Family at all but a 2nd Family liaison without a partner. In other words, any scenario where the last Family is a liaison without a partner, and an earlier Family with Spouse exists.

I accept that those are comparatively rare scenarios, but it is quite easy to make it foolproof by using:
fhGetItemText(pi,'~.~SPOU[1]>')..fhGetItemText(pi,'~.~SPOU[2]>')..fhGetItemText(pi,'~.~SPOU[3]>')
and extend it with SPOU[4] et seq as far as necessary.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 06 Nov 2016 15:27

Mike

I checked this out with a simple query and using ~SPOU[<20] (and I do mean twenty) in all the families in my file (maximum of 3 spouses) this picked out the last spouse BUT I have no families of the type you mentioned. So I constructed one and annoyingly it then returned a blank. I guess I will have to make the change you suggested thank you.

When I have changed that I should be ready to post an update which at least goes some way towards addressing the Last Updated problem.

David

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 06 Nov 2016 16:08

Mike

My main aim in using the avatars with a plus was to give a visual indication in the focus window as to which children had more relatives to see if selected, It occurs to me after this discussion that I failed to allow for the possibility of children and no spouses, My reading of the FH help file suggests that this might be easier but before I commit myself would the folloiwng addition to your text do the job?

fhGetItemText(pi,'~.~SPOU[1]>')..fhGetItemText(pi,'~.~SPOU[2]>')..fhGetItemText(pi,'~.~SPOU[3]>')..fhGetItemText(pi,'~.~CHIL[1]>')

David

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 06 Nov 2016 18:04

Yes David, that will add the case of one or more single parent families with one or more children and no spouses.

But thinking about it, if that is what you want then all your need is fhGetItemText(pi,'~.FAMS[1]>')
because a Family as Spouse (FAMS) entry can only exist is there is a Child or a Spouse i.e. 2 partners.
It should not be possible for a FAMS entry to exist with just one parent.
i.e. There must be at least two WIFE, HUSB, or CHIL links.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 06 Nov 2016 19:10

One of the joys, and problems, with FH is that you can do a great many things that you shouldn't be able to do. Earlier when I was thinking about this I added a Spouse family link to my grandson's record and he has no children and no spouse. Of course I cheated a bit by adding it via the All tab. He is listed as the Husband in the record but apart from that it is empty.

I think I will stick with the slightly longer way of deciding whether they are 'Plus'. I still haven't got round to making the alterations but I will.

David

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 06 Nov 2016 21:09

Yes David, you can cheat FH like that, but the Show Project Statistics Plugin comes to your aid.
It detects uncommon Family record structures such as single parent families with and without children.
So it is quite easy to check for those anomalies and eliminate them, or simply wait until you discover them by accident, as it does no real harm to have a slightly inaccurate avatar here and there that has a + it should not have.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 07 Nov 2016 08:51

A final version, I hope, or at least until another problem arises.
Attach Avatars Revisited.fh_lua
(4.82 KiB) Downloaded 187 times

User avatar
tatewise
Megastar
Posts: 27089
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Adding 'avatars' to individuals

Post by tatewise » 07 Nov 2016 11:56

David, when I run that for the first time on say the Famly Historian Sample Project then ALL the existing Individual Media tab image links are deleted in InsertAvatar(...) by the code:

if (#tdis>=3 and string.sub(tdis,1,3)~='** ') then
fhDeleteItem(pob)
else

and replaced by the one ** avatar image link.
I presume that is not intentional?

There is a snag with retaining existing preferred images by putting (Avatar) in the Media Title.
If the same Media is linked to several Individuals, and may use Link to Face frame part images, then putting (Avatar) in the Media Title affects ALL those Individuals.
There is no obvious solution.

Presumably, the Avatar icons should not be included in Reports so their Exclude from Reports option should be set throughout.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
DavidNewton
Superstar
Posts: 462
Joined: 25 Mar 2014 11:46
Family Historian: V7

Re: Adding 'avatars' to individuals

Post by DavidNewton » 07 Nov 2016 12:23

Thanks Mike

I just came across that mistake when doing some deeper testing. Unfortunately I have very few individuals with more than one media record attached so that error slipped past me. It should read == as opposed to ~=. There is also another error in that loop as I have mismatched the index: OBJE should be OBJE['..i..']'

My original intention with this was to supply avatar images for individual records with no attached media and then of course the InsertAvatar function which has caused me grief is not needed. I am attaching a corrected version of the previous plugin but I feel that at this time we have probably spent enough time on this. I have learn't a lot thank you.

David
Attach Avatars Revisited.fh_lua
(4.89 KiB) Downloaded 120 times
Added in edit: I have left some debugging code in InsertAvatar regarding a particular record it should be deleted.

Post Reply