* Plugin to remove all ADDResses attempt

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.
Post Reply
User avatar
jimlad68
Megastar
Posts: 911
Joined: 18 May 2014 21:01
Family Historian: V7
Location: Sheffield, Yorkshire, UK (but from Lancashire)
Contact:

Plugin to remove all ADDResses attempt

Post by jimlad68 » 19 Mar 2022 22:33

I have finally got around to creating a simple Plugin to remove all ADDResses. I know there are workarounds, the Rearrange Address and Place Parts Plugin and simply listing them in a query, selecting then deleteing. But it is about time I at least attempted something simple.

My attempt here is based on the FH plugin Help example Find Date Phrases.
It works, BUT, only does 1 at a time.
I did have a version using ptrItem:MoveToFirstRecord(strType) instead of strTypeDesc which did 2 at a time??

Code: Select all

tblTypes = {'INDI','FAM'} -- Scan both Family and Individual Record Types
ptrItem = fhNewItemPtr()

for iType,strTypeDesc in ipairs(tblTypes) do
    ptrItem:MoveToFirstRecord(strTypeDesc)

    while ptrItem:IsNotNull() do
        strType = fhGetTag(ptrItem)

        if strType == 'ADDR' then -- Search items until ADDR field found
            fhDeleteItem(ptrItem)

        end
        ptrItem:MoveNextSpecial()
    end
end
Jim Orrell - researching: see - but probably out of date https://gw.geneanet.org/jimlad68

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

Re: Plugin to remove all ADDResses attempt

Post by tatewise » 20 Mar 2022 10:32

That is an excellent attempt.
Unfortunately, the ptrItem:MoveNextSpecial() statement is disrupted by the fhDeleteItem(ptrItem) statement that forces the ptrItem value to be null and thus terminates the MoveNextSpecial() loop.

The trick is to add each ADDR ptrItem to a table and then at the end loop through the table deleting items.
e.g.
local tblAddr = {} -- near start

table.insert( tblAddr, ptrItem:Clone() ) -- instead of fhDeleteItem(ptrItem) -- :Clone() is important

for i, ptrAddr in pairs ( tblAddr ) do -- after end
fhDeleteItem(ptrAddr)
end
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
jimlad68
Megastar
Posts: 911
Joined: 18 May 2014 21:01
Family Historian: V7
Location: Sheffield, Yorkshire, UK (but from Lancashire)
Contact:

Re: Plugin to remove all ADDResses attempt

Post by jimlad68 » 20 Mar 2022 12:57

Thanks, that works fine. So to overcome the MoveNextSpecial limitation/problem, instead of 1 loop we split into 2 parts.
I did a Notepad++ compare of before and after with no unexpected changes (just 2_ADDR and TIME)

So, next tasks:
- Study the for i, itype, ipairs etc (I suspect a start from scratch looking through the "How to write plugins" and even the linked http://www.lua.org/manual/5.3/, but up to now I cannot find much on itype.
- Look at fhOutputResultSet to see what has been done.

Code: Select all

tblTypes = {'INDI','FAM'} -- Scan both Family and Individual Record Types
local tblAddr = {} 
-- ################## collect ADDResses in table
ptrItem = fhNewItemPtr()
for iType,strTypeDesc in ipairs(tblTypes) do
    ptrItem:MoveToFirstRecord(strTypeDesc)
    while ptrItem:IsNotNull() do
        strType = fhGetTag(ptrItem)
        if strType == 'ADDR' then -- Search items until ADDR field found
            -- fhDeleteItem(ptrItem)
            table.insert( tblAddr, ptrItem:Clone() )
        end
        ptrItem:MoveNextSpecial()
    end
end
-- ################# then delete
for i, ptrAddr in pairs ( tblAddr ) do 
    fhDeleteItem(ptrAddr)
end
Last edited by jimlad68 on 21 Mar 2022 10:36, edited 1 time in total.
Jim Orrell - researching: see - but probably out of date https://gw.geneanet.org/jimlad68

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

Re: Plugin to remove all ADDResses attempt

Post by tatewise » 20 Mar 2022 13:36

Yes, quite often plugins will have several loops or phases to complete the task.

Have you found the FHUG Knowledge Base Family Historian Plugins section.
Especially, Getting Started Writing Plugins and Lua References and Library Modules.

for is a fundamental Lua language looping keyword and ipairs(...) is a standard function found in the language index.

i and iType are simple integer variables that count the loops.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
jimlad68
Megastar
Posts: 911
Joined: 18 May 2014 21:01
Family Historian: V7
Location: Sheffield, Yorkshire, UK (but from Lancashire)
Contact:

Re: Plugin to remove all ADDResses attempt

Post by jimlad68 » 20 Mar 2022 14:20

Yes, thanks for reminding me of those links and simple explanation of the "i" bits. I think doing a simple task "from scratch" that I will find useful has given me more confidence. It is feeling a bit more like my MS VBA "tinkerings" and for me a big step up from basic scripting, now all I need is time.
Jim Orrell - researching: see - but probably out of date https://gw.geneanet.org/jimlad68

User avatar
Vyger
Platinum
Posts: 41
Joined: 15 Jan 2019 12:11
Family Historian: V7

Re: Plugin to remove all ADDResses attempt

Post by Vyger » 20 Mar 2022 15:00

@jimlad68, may I ask why, origins of Address data, desired goal?

I ask because I still maintain my extensive Address (Place Details) database in Rootsmagic 7, it's an extensive work and too valuable for me to forsake, it remains my last link to the Rootsmagic and will do until CP fill that gap.

Other programs already make value added use of such possible enhanced data so I do believe the day of relational Addresses including geocoding and other attachments will come to FH.

Each to their own but I only ask your reasons as I always think long and hard before knocking something down which took so long to build in my case. The fact FH does not make much use of this valuable data item is certainly no reason for me personally to scrap them so I'm just interested in your reasons?
Genealogy Reviews - research methods for a more productive future

User avatar
jimlad68
Megastar
Posts: 911
Joined: 18 May 2014 21:01
Family Historian: V7
Location: Sheffield, Yorkshire, UK (but from Lancashire)
Contact:

Re: Plugin to remove all ADDResses attempt

Post by jimlad68 » 20 Mar 2022 17:22

Vyger wrote:
20 Mar 2022 15:00
OK, I will give you a past topic link and there are other links from there.
https://www.fhug.org.uk/forum/viewtopic ... 849#p71849

If you don't want to read all that, as regards to ADDResses the jist of it is.
- I keep all my "location" info in the PLACe record, the usual 10 levels separated by commas.
- I use the ADDRess records as an abbreviated version of the PLACe to use in Diagrams where using the full PLACe clutters up the diagram and FH abbreviations do not suit me.
- Hence as part of my ADDR update procedure I have a plugin to abbreviate the PLACe to ADDRess. The reason for my wanting to delete all ADDRs is that the plugin only works with empty ADDRs. I will now hopefully combine the 2 plugins so it is a quick process. If anyone is interesed I will post it later, but very bespoke to my data setup.
- My diagram Text Scheme has an option so that if the ADDR is not there (for say new items) it reverts to PLACe.
See attached.
Attachments
0-MAIN ConcisePrint-05-## +RECORD ID +Address or PLAC if no addr##.fht
text scheme with ADDR - PLACE if no ADDR
(22.26 KiB) Downloaded 43 times
Jim Orrell - researching: see - but probably out of date https://gw.geneanet.org/jimlad68

User avatar
Vyger
Platinum
Posts: 41
Joined: 15 Jan 2019 12:11
Family Historian: V7

Re: Plugin to remove all ADDResses attempt

Post by Vyger » 20 Mar 2022 20:43

Thank you, we all work in different ways, needs must.
Genealogy Reviews - research methods for a more productive future

Post Reply