Page 1 of 1
Handling Fact Flags in a plugin
Posted: 08 Aug 2023 15:14
by quarlton
I'm writing a plugin to set the 'Preferred' flag on all BIRT events.
[This relates to
https://groups.io/g/family-historian/message/7112 - Highlight or Colour Facts on the property box]
Following Mike's code above I can check if the flag already exists, so skip to next INDI.
I can create the tag OK, but can't work out how to set the value.
Code: Select all
--Create a Flag tag on the BIRT
--ptrFlag2 is a pointer to the BIRT event
local ptrFlagNew = fhCreateItem("_FLGS", ptrFlag2) -- This works fine and creates the tag
fhSetValueAsText(ptrFlagNew, "Preferred") -- This fails
I've searched the FH plugin guide and this forum but can't find the right syntax.
Any help would be much appreciated
Re: Handling Fact Flags in a plugin
Posted: 08 Aug 2023 15:58
by tatewise
Dave, I have started a new thread because the
Handling Custom Flags in a plugin (17518) thread you used focuses on Individual Record Flags not Fact Flags.
As I often suggest, the way to discover FH/GEDCOM codes is to use any FH Data Reference Assistant as follows.
Open the Query > Relatives and Relationships > All Individuals and open the Columns tab.
Below the box below the Fields, use the small triangular button to Show Both in Box.
Then in Fields, choose Events + Birth + Flags + Preferred to reveal Preferred fact flag %INDI.BIRT[1]._FLGS.__PREFERRED%
I'm unsure whether "__PREFERRED" is set as a text value or must be created just like the "_FLGS" tag (I suspect the latter).
BTW: Make sure you are actually checking the BIRT event and remember that any combination of Fact Flags can be set.
Re: Handling Fact Flags in a plugin
Posted: 08 Aug 2023 16:53
by quarlton
Thanks for that Mike.
Unfortunately I haven't managed to find the correct syntax for setting the value for the tag.
I'll persevere and see what I can come up with.
Re: Handling Fact Flags in a plugin
Posted: 08 Aug 2023 17:38
by tatewise
The syntax is the same as you are already using:
local ptrFlagNew = fhCreateItem("_FLGS", ptrFlag2)
But the item you're creating is "__PREFERRED" and the parent is ptrFlagNew.
Are you sure that ptrFlag2 is pointing to a BIRT event tag?
Try stepping through the plugin script in the debugger one line at a time by setting a breakpoint in the lefthand margin.
If ptrFlag2 is pointing to a BIRT event then the birth details should be shown as its Value in lower right pane.
If you really cannot get it to work then post your entire script here.
I could post a solution, but learning debug techniques are a good exercise.
Re: Handling Fact Flags in a plugin
Posted: 08 Aug 2023 20:00
by quarlton
Hi Mike
Thanks for that, it works a treat
Code: Select all
--Create a Flag tag on the BIRT
--ptrFlag2 is a pointer to the BIRT event
local ptrFlagNew = fhCreateItem("_FLGS", ptrFlag2) -- This creates the tag
local ptrFlagNew2 = fhCreateItem("__PREFERRED", ptrFlagNew) -- This sets the value
Regards
Re: Handling Fact Flags in a plugin
Posted: 08 Aug 2023 20:31
by tatewise
FYI: The final script I came up with is as below and checks every Birth Event for every Individual.
It caters for multiple Birth Events for one Individual and checks before adding the Preferred Flag to each one.
It could be extended to cater for other key Individual events, but needs an alternative method for Family events like Marriage.
It is left to the reader to make those amendments...
Code: Select all
local ptrIndi = fhNewItemPtr()
ptrIndi:MoveToFirstRecord("INDI")
while ptrIndi:IsNotNull() do -- Check each Individual
local ptrBirt = fhGetItemPtr(ptrIndi,"~.BIRT")
while ptrBirt:IsNotNull() do -- Check each Birth Event
local ptrFlag = fhGetItemPtr(ptrBirt,"~._FLGS")
if ptrFlag:IsNull() then -- Ensure the Fact Flags tag exists
ptrFlag = fhCreateItem("_FLGS", ptrBirt)
end
if ptrFlag:IsNotNull() then -- Check if Preferred Flag exists
local ptrPref = fhGetItemPtr(ptrFlag,"~.__PREFERRED")
if ptrPref:IsNull() then -- Ensure Preferred Flag is added
ptrPref = fhCreateItem("__PREFERRED", ptrFlag)
end
end
ptrBirt:MoveNext("SAME_TAG")
end
ptrIndi:MoveNext()
end