*how to get #entries.

Writing and using plugins for Version 5 and above.
Ron Melby
Famous
Posts: 217
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

how to get #entries.

Postby Ron Melby » 08 Feb 2019 18:36

so, I am trying to determine, (since it should be non-nil if it exists)
how do I get the NAME[ ], SPOU[], MARR[] and so on, number of entries?

nent = #NAME
sent = #SPOU
ment = #MARR

That isnt going to work, I know that before I even test it.
Win 7 64 bit. FH V.6.2.6

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

Re: how to get #entries.

Postby tatewise » 08 Feb 2019 19:32

You are correct the # length operator only applies to Lua data items and not GEDCOM structures.
Unfortunately, you have to count them using a while loop.
e.g.

Code: Select all

local ptrIndi = fhNewItemPtr()
ptrIndi:MoveToFirstRecord("INDI")
while ptrIndi:IsNotNull() do
   local intName = 0
   local ptrName = fhNewItemPtr()
   ptrName:MoveTo(ptrIndi,"~.NAME")
   while ptrName:IsNotNull() do
      intName = intName + 1
      ptrName:MoveNext("SAME_TAG")
   end
   print(intName)
   ptrIndi:MoveNext()
end

You could make the counting loop a function with parameter (ptrItem) and return the count.
e.g.

Code: Select all

local function intInstances(ptrItem)   -- Count number of instances of Item
   local intItem = 0
   while ptrItem:IsNotNull() do
      intItem = intItem + 1
      ptrItem:MoveNext("SAME_TAG")
   end
   return intItem
end -- local function intInstances

local ptrIndi = fhNewItemPtr()
ptrIndi:MoveToFirstRecord("INDI")
while ptrIndi:IsNotNull() do
   local intName = intInstances( fhGetItemPtr(ptrIndi,"~.NAME") )
   print(intName)   -- Diagnostic printout of instances
   ptrIndi:MoveNext()
end

Then you can use function intInstances to count any data item instances.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Ron Melby
Famous
Posts: 217
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: how to get #entries.

Postby Ron Melby » 08 Feb 2019 22:03

thats sort of what my code looks like

I thought first #NAME, realized while it looks ok, its just a text string, and wont work
then I thought about pairs, but if there is a table behind it I cant get at it.

strDataOffset = "~.NAME[" .. ln .. "]:SURNAME_FIRST"
is what I ended up with

where ln is the last name in the structure
and it works fairly well for what I want, but doesnt account for non-marraiges, husbands I dont know, and children out of wedlock..but I can work with it.
Win 7 64 bit. FH V.6.2.6

Ron Melby
Famous
Posts: 217
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: how to get #entries.

Postby Ron Melby » 08 Feb 2019 22:09

sideways a little from the subject, but still this plugin, so if it needs moving...

reading what I can find of the spec: require can be anywhere in the file, is that correct?

also, I have been trying to come to grips with coroutines and fhUpdateDisplay() trying to find a way to update the output tables when I make a change from the screen, and do not think it is possible, or am I missing something?
Win 7 64 bit. FH V.6.2.6

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

Re: how to get #entries.

Postby tatewise » 08 Feb 2019 22:34

I think require needs to executed before the components of the module are called.
Usually the require is invoked at the very start of the Plugin. Why put it anywhere else?

coroutines are quite tricky, especially since you still seem to be struggling to grasp more basic concepts.
How were you hoping to use coroutines?

fhUpdateDisplay() only applies to windows that were on display in FH before the Plugin was run.
It cannot possibly apply to the Result Set output because that does not exist until after the Plugin has completed.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Ron Melby
Famous
Posts: 217
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: how to get #entries.

Postby Ron Melby » 08 Feb 2019 22:38

then what I want doesnt appear to be doable.
Win 7 64 bit. FH V.6.2.6


Return to “Plugin Discussions”

Who is online

Users browsing this forum: No registered users and 2 guests