* Clone any Record query (literally!)

Writing and using plugins for Version 5 and above.
Post Reply
avatar
Mark1834
Famous
Posts: 233
Joined: 27 Oct 2017 19:33
Family Historian: V6.2
Location: South Cheshire

Clone any Record query (literally!)

Post by Mark1834 » 28 Oct 2020 18:36

A new set of parish registers that are very relevant to my research have been uploaded to Ancestry recently. To help me work through the relevant records in my project, I have constructed a simple query to list those that are more likely to be relevant (e.g. births in that parish without a baptism currently listed). I use the "Clone any Record" plug-in to create new source records from a template, but unfortunately, the output of the plug-in blows away the tabulated query results every time I run it, so I have to re-run the query to recreate the table.

Two related questions please -

1. Is it possible to keep the query results intact while running the plug-in as defined, or are they competing for the same table to output results?

2. It looks like a very simple plug-in, so modifying it to produce a version that just clones a Source Record without producing any other output should be a simple example to practice my (weak and rather stale) Lua skills. I was a bit puzzled by seeing the BuildDR function definition apparently within an else-end block of code. Without trying to second-guess the author, is there a fundamental reason for that, or is it just programming style? I've tried moving it to the top of the script with the other definitions, and the plug-in seems to work ok.

Thanks.
Mark Draper

User avatar
ColeValleyGirl
Megastar
Posts: 1785
Joined: 28 Dec 2005 22:02
Family Historian: V6.2
Location: Cirencester, Gloucestershire
Contact:

Re: Clone any Record query (literally!)

Post by ColeValleyGirl » 28 Oct 2020 18:42

Right click on the Query window and Lock it before running the plugin -- does that help?

avatar
Mark1834
Famous
Posts: 233
Joined: 27 Oct 2017 19:33
Family Historian: V6.2
Location: South Cheshire

Re: Clone any Record query (literally!)

Post by Mark1834 » 28 Oct 2020 19:26

Thanks Helen - easy when you know how :) Even three years into FH, I'm still finding new features, and have now worked out that you can also set your preferences to lock all query windows automatically. I think I'll leave that set, as I frequently use query outputs for more extended operations.
Mark Draper

User avatar
tatewise
Megastar
Posts: 19152
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Clone any Record query (literally!)

Post by tatewise » 28 Oct 2020 19:26

You can also use Tools > Preferences > Workspaces and set Re-use... for Query Window to No.

Lua is quite relaxed about where items are defined.
As it happens, BuidDR is a global function so it could be defined anywhere prior to it being called.
If it were a local function it woud have to be defined in scope prior to it being called.
But in this very simple script the only out-of-scope region would be in the if-else block.
Its current position is just the author's style.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
Mark1834
Famous
Posts: 233
Joined: 27 Oct 2017 19:33
Family Historian: V6.2
Location: South Cheshire

Re: Clone any Record query (literally!)

Post by Mark1834 » 28 Oct 2020 19:37

Thanks Mike - most of my current coding is done in Python (Linux/Raspberry Pi, as well as a powerful tool for direct manipulation of GEDCOM files), and that uses indentation rather than end statements or curly braces to denote distinct code blocks. The definition looked distinctly odd in Python terms, so I have to retrain myself to be white-space agnostic again....
Mark Draper

User avatar
tatewise
Megastar
Posts: 19152
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Clone any Record query (literally!)

Post by tatewise » 28 Oct 2020 19:45

I have to admit that I would not have written that function definition in that position. It is odd in Lua terms too!
Although not strictly necessary, most programmers do indent the Lua script to match the blocks.
I presume you have found the Knowledge Base > FH Plugins > Developer Guide with its Getting Started Writing Plugins.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
Mark1834
Famous
Posts: 233
Joined: 27 Oct 2017 19:33
Family Historian: V6.2
Location: South Cheshire

Re: Clone any Record query (literally!)

Post by Mark1834 » 29 Oct 2020 18:35

After a bit of reading and trial and error, I've reduced the public plug-in to the following code for the special case of cloning a source, which is all I use it for. It seems to work ok, even on sources with multiple attached media records.

Code: Select all

tblT = fhGetCurrentRecordSel('SOUR')

if #tblT ~= 1 then return end 

ptrSource = tblT[1]
ptrTarget = fhCreateItem('SOUR')

p1 = fhNewItemPtr()
p1:MoveToFirstChildItem(ptrSource)

while not p1:IsNull() do
	p2 = fhCreateItem(fhGetTag(p1), ptrTarget)
	fhSetValue_Copy(p2, p1)
	p1:MoveNext()
end

s = 'Source #'..fhGetRecordId(ptrSource)..' ('..fhGetDisplayText(ptrSource)..') copied as new source #'..fhGetRecordId(ptrTarget)
fhMessageBox(s, 'MB_OK', 'MB_ICONINFORMATION')

It's a lot simpler than even the simple plug-in, but doesn't need to cater for more than one level of child pointers as far as I can see.
Mark Draper

User avatar
tatewise
Megastar
Posts: 19152
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Clone any Record query (literally!)

Post by tatewise » 29 Oct 2020 18:46

Yes, a plugin created for your very specific purpose is likely to be much simpler than any public published plugin.
A public plugin must cater for copying any type of record, not just sources, and so must handle multiple levels.
It also usually needs a user friendly interface dialogue which your private plugin does not.

FYI: It is possible to have more than one level of tags in a Source, but you are unlikely to have created them.
The way to check is to create a dummy blank Source record and on its All tab right-click and add everything possible.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
Mark1834
Famous
Posts: 233
Joined: 27 Oct 2017 19:33
Family Historian: V6.2
Location: South Cheshire

Re: Clone any Record query (literally!)

Post by Mark1834 » 31 Oct 2020 12:23

When using the public plug-in, it is very noticeable that the run time increases significantly once FH has been open for a while, from near instantaneous to perhaps a 2-3 second lag before the result is presented. Presumably FH is doing a less than perfect job in managing its use of resources, and either the recursive function calls or table building are relatively resource-heavy, as the simple copy script has stayed virtually instantaneous even after many hours of use without an overnight boot to reset the program.
Mark Draper

User avatar
tatewise
Megastar
Posts: 19152
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Clone any Record query (literally!)

Post by tatewise » 31 Oct 2020 13:22

It is difficult to pin down such effects and causes.
Certainly, a resource-hungry feature is the Result Set, and if it gets large can take many minutes to appear.
Strangely, a Query Result Set with similar rows & columns was typically about 25 times faster.
I reported this to Calico Pie under the subject Large Result Sets Very Slow in Jan 2016 and they made some improvements in V6.1.3 but I have lost track of how significant they were.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Post Reply