* Show a plugin prepared citation
Show a plugin prepared citation
I have a plugin that, based on the content of the clipboard, neatly creates a templated source record. But I have to select the newly created source myself to check it and add things like media.
Is it possible to add a statement to the plugin to have the created source selected and shown by the plugin? And, if so how?
Is it possible to add a statement to the plugin to have the created source selected and shown by the plugin? And, if so how?
- ColeValleyGirl
- Megastar
- Posts: 5499
- Joined: 28 Dec 2005 22:02
- Family Historian: V7
- Location: Cirencester, Gloucestershire
- Contact:
Re: Show a plugin prepared citation
There isn't anything in the FH API which will do that. However, if you output a results set that includes a pointer to the source, you can select it to open from the results set -- which may be marginally quicker (depending on how you are opening things now.
I haven't tried it, but one option might be to make your plugin a DEA -- workflow might be something like:
I haven't tried it, but one option might be to make your plugin a DEA -- workflow might be something like:
- Prepare a citation to a source of the correct template but leave all the fields blank.
- Run your plugin as a DEA to populate the fields(while the prepared citation is still open) -- don't create a results set so the prepared citation retains the focus
- Refresh the FH Display so that your changes appear in the prepared citation
- Check, add things like media etc.
Helen Wright
ColeValleyGirl's family history
ColeValleyGirl's family history
Re: Show a plugin prepared citation
Hi Helen,
Too bad, there isn't. I've been considering a result set also, but it's not better than what I do now (select the newly generated source in the yellow auto bar on top).
I'll checkout the DEA approach; good idea.
As to why the plugin doesn't add the media:
The plugin is written for www.wiewaswie.nl. This site is meant to be the entry to online genealogy records and is well underway to get there. That is in as far as transcribed data goes. For the scans of the actual certificates there is usually a link to the original archive sites.
So, my workflow is:
1. Find the record and print it (doesn't really print, but shows the data in a standard and neat format).
2. Copy that to the clipboard.
3. Run the plugin (all template fields are created and text to source is filled).
4. If a scan is available somewhere, follow the link and download it.
5. Add the location data of the scan to the source template.
6. Cleanup the scan and save it with the name of the source.
7. Add the scan to the media tab and complete the fields there.
8. Check the template fields with the scan data (there may be differences).
9. Add the data to the relevant facts.
Too bad, there isn't. I've been considering a result set also, but it's not better than what I do now (select the newly generated source in the yellow auto bar on top).
I'll checkout the DEA approach; good idea.
As to why the plugin doesn't add the media:
The plugin is written for www.wiewaswie.nl. This site is meant to be the entry to online genealogy records and is well underway to get there. That is in as far as transcribed data goes. For the scans of the actual certificates there is usually a link to the original archive sites.
So, my workflow is:
1. Find the record and print it (doesn't really print, but shows the data in a standard and neat format).
2. Copy that to the clipboard.
3. Run the plugin (all template fields are created and text to source is filled).
4. If a scan is available somewhere, follow the link and download it.
5. Add the location data of the scan to the source template.
6. Cleanup the scan and save it with the name of the source.
7. Add the scan to the media tab and complete the fields there.
8. Check the template fields with the scan data (there may be differences).
9. Add the data to the relevant facts.
Re: Show a plugin prepared citation
I changed the plugin to the DEA type, created a source and ran the DEA.
The prepared citation screen I ended up with was blank prepared citation window (a new empty extra source was created) , but the intended source was generated correctly.
So everything seems to work except the creation of an extra source. Any ideas why this might happen?
The prepared citation screen I ended up with was blank prepared citation window (a new empty extra source was created) , but the intended source was generated correctly.
So everything seems to work except the creation of an extra source. Any ideas why this might happen?
- ColeValleyGirl
- Megastar
- Posts: 5499
- Joined: 28 Dec 2005 22:02
- Family Historian: V7
- Location: Cirencester, Gloucestershire
- Contact:
Re: Show a plugin prepared citation
When you prepare a citation using Create Source from... the first thing it does is create an empty source. If your plugin also creates a source, you'll end up with two sources. Your plugin should modify the source FH creates rather than create another one.
Helen Wright
ColeValleyGirl's family history
ColeValleyGirl's family history
Re: Show a plugin prepared citation
Hi Helen, I see, but how do I get the pointer to the empty source?
- ColeValleyGirl
- Megastar
- Posts: 5499
- Joined: 28 Dec 2005 22:02
- Family Historian: V7
- Location: Cirencester, Gloucestershire
- Contact:
Re: Show a plugin prepared citation
Try (not tested)
The prepared citation (tag _PCIT) is stored in the Header record, and contains a ptr to the associated Source.
Code: Select all
local ptrBase:MoveToFirstRecord('HEAD')
local ptr = fhGetItemPtr(ptrBase,'~._PCIT')
local ptrSource = fhGetItemPtr(ptr,'~.SOUR>')
Helen Wright
ColeValleyGirl's family history
ColeValleyGirl's family history
Re: Show a plugin prepared citation
Thanks a lot Helen!
It works beautifully.
It works beautifully.
Re: Show a plugin prepared citation
Hi Helen,
About your suggestion to also add the media when the plugin creates the source record. Maybe, with a slight change of my workflow, it could work. But I need some help here.
The data available at the moment I create the source (related to the Media record) is:
1. Name of media record (= Title of source record)
2. Date of Media record (= Source date)
3. Keyword (= derived of Source type)
4. Filename (the path is unknown, but I think it can be derived of the source type)
But at the moment of creation of the source the actual file may not yet be there.
So, I guess I can create a Media object and add the above named fields? But how do I link the actual file later, or will it automatically appear in the media tab when the link (nr. 4 above) is actually linked to the file?
About your suggestion to also add the media when the plugin creates the source record. Maybe, with a slight change of my workflow, it could work. But I need some help here.
The data available at the moment I create the source (related to the Media record) is:
1. Name of media record (= Title of source record)
2. Date of Media record (= Source date)
3. Keyword (= derived of Source type)
4. Filename (the path is unknown, but I think it can be derived of the source type)
But at the moment of creation of the source the actual file may not yet be there.
So, I guess I can create a Media object and add the above named fields? But how do I link the actual file later, or will it automatically appear in the media tab when the link (nr. 4 above) is actually linked to the file?
- ColeValleyGirl
- Megastar
- Posts: 5499
- Joined: 28 Dec 2005 22:02
- Family Historian: V7
- Location: Cirencester, Gloucestershire
- Contact:
Re: Show a plugin prepared citation
You can create the media record (don't forget the file type) including the file path and name and it will look like a broken external file link until you put the media file in the right place in the filing system.
Helen Wright
ColeValleyGirl's family history
ColeValleyGirl's family history
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Show a plugin prepared citation
The format for the File Link will depend on where you intend to hold the Media file.
If outside the FH Project, then it must be the full absolute file path starting from the drive letter.
If inside the Project folder, then it will start with Media\ then any sub-folder and then the filename, i.e. a file path relative to the Project .fh_data folder.
If outside the FH Project, then it must be the full absolute file path starting from the drive letter.
If inside the Project folder, then it will start with Media\ then any sub-folder and then the filename, i.e. a file path relative to the Project .fh_data folder.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: Show a plugin prepared citation
Yes Mike, and since I use external files and in this workflow the path is still unknown, the only option would be to ask the user to enter the path. This however, would nullify the potential workflow benefit.
Another option might be a slightly modified version of the Rename Source Media plugin (say: Complete Source Media plugin).
The workflow could then be:
1. Run the WieWasWie DEA plugin (this will take care of the meta fields an Text to Source).
2. Copy the Media file to the media tab.
3. Run the Complete Source Media plugin, which will then:
a. Copy the Media title to the Source title.
b. Copy the Media Date to the Source document date.
c. Set a keyword based on the source type.
d. If necessary rename the file and set the Media file link to this filename.
Could this work or am I missing something?
Another option might be a slightly modified version of the Rename Source Media plugin (say: Complete Source Media plugin).
The workflow could then be:
1. Run the WieWasWie DEA plugin (this will take care of the meta fields an Text to Source).
2. Copy the Media file to the media tab.
3. Run the Complete Source Media plugin, which will then:
a. Copy the Media title to the Source title.
b. Copy the Media Date to the Source document date.
c. Set a keyword based on the source type.
d. If necessary rename the file and set the Media file link to this filename.
Could this work or am I missing something?
- ColeValleyGirl
- Megastar
- Posts: 5499
- Joined: 28 Dec 2005 22:02
- Family Historian: V7
- Location: Cirencester, Gloucestershire
- Contact:
Re: Show a plugin prepared citation
Your approach should work but it's getting a little complicated. I might be tempted to do the Media handling that has to be done outside the DEA before invoking the DEA, but that's a change to your workflow so may not work for you.
Helen Wright
ColeValleyGirl's family history
ColeValleyGirl's family history
Re: Show a plugin prepared citation
Yes Helen, I've considered that approach too, but I'm not sure about how to improve on my workflow and optimize the usage of the DEA.
In essence what I do is:
1. Use WieWasWie to get the transcription of the data
2. Create a source from template
3. Start my plugin (DEA) to process this data
4. Follow a link on the WieWasWie page to go to the scanned image of the certificate and download it
5. Add the online-location (e.g. page number in a book) of the scan and the URL to the source
6. Add the scan to the source
7. Type in the media title, date and keyword
So, it's really about how to improve on steps 6 and 7. That is, making sure that the naming (source title, media name, filename) and dating is consistent is my primary objective.
Suggestions are very welcome.
In essence what I do is:
1. Use WieWasWie to get the transcription of the data
2. Create a source from template
3. Start my plugin (DEA) to process this data
4. Follow a link on the WieWasWie page to go to the scanned image of the certificate and download it
5. Add the online-location (e.g. page number in a book) of the scan and the URL to the source
6. Add the scan to the source
7. Type in the media title, date and keyword
So, it's really about how to improve on steps 6 and 7. That is, making sure that the naming (source title, media name, filename) and dating is consistent is my primary objective.
Suggestions are very welcome.
- ColeValleyGirl
- Megastar
- Posts: 5499
- Joined: 28 Dec 2005 22:02
- Family Historian: V7
- Location: Cirencester, Gloucestershire
- Contact:
Re: Show a plugin prepared citation
In that case, I'd follow your steps 1 to 5, then add the scan by dragging and dropping it into the Media tab for the prepared citation, and run a DEA to do the naming and dating.
The DEA would be a version of the plugin your posted in another thread, but operating only on the source/media for the prepared citation.
The DEA would be a version of the plugin your posted in another thread, but operating only on the source/media for the prepared citation.
Helen Wright
ColeValleyGirl's family history
ColeValleyGirl's family history
Re: Show a plugin prepared citation
Yes, I came to the same conclusion and already began writing it.
Thanks for the help and discussion.
Thanks for the help and discussion.
Re: Show a plugin prepared citation
I am missing something.
I have a pointer pMedia to a media record.
I can set the file name as the media title with:
pFile:MoveTo(pMedia,'~>FILE')
local pTitle = fhNewItemPtr()
pTitle:MoveTo(pFile,'~.TITL')
fhSetValueAsText(pTitle,sTitle)
But setting the date with:
dDate = fhGetValueAsDate(fhGetItemPtr(pSource,'~.~DT-DATUM'))
local pDate = fhNewItemPtr()
pDate:MoveTo(pMedia,'~._DATE')
fhSetValueAsDate(pDate,dDate)
Doesn't work. Same for the Keyword with:
sType = fhGetValueAsText(fhGetItemPtr(pSource, '~.~EN-TYPE'))
local pType = fhNewItemPtr()
pType:MoveTo(pMedia,'~._KEYS')
fhSetValueAsText(pType,sType)
What am I doing wrong?
I have a pointer pMedia to a media record.
I can set the file name as the media title with:
pFile:MoveTo(pMedia,'~>FILE')
local pTitle = fhNewItemPtr()
pTitle:MoveTo(pFile,'~.TITL')
fhSetValueAsText(pTitle,sTitle)
But setting the date with:
dDate = fhGetValueAsDate(fhGetItemPtr(pSource,'~.~DT-DATUM'))
local pDate = fhNewItemPtr()
pDate:MoveTo(pMedia,'~._DATE')
fhSetValueAsDate(pDate,dDate)
Doesn't work. Same for the Keyword with:
sType = fhGetValueAsText(fhGetItemPtr(pSource, '~.~EN-TYPE'))
local pType = fhNewItemPtr()
pType:MoveTo(pMedia,'~._KEYS')
fhSetValueAsText(pType,sType)
What am I doing wrong?
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Show a plugin prepared citation
You probably need to create the _DATE and _KEYS fields as they do not exist by default.
local pDate = fhCreateItem( "_DATE", pMedia, true )
To double-check ...
local pDate = fhNewItemPtr()
pDate:MoveTo(pMedia,'~._DATE')
if pDate:IsNull() then
pDate = fhCreateItem( "_DATE", pMedia, true )
end
local pDate = fhCreateItem( "_DATE", pMedia, true )
To double-check ...
local pDate = fhNewItemPtr()
pDate:MoveTo(pMedia,'~._DATE')
if pDate:IsNull() then
pDate = fhCreateItem( "_DATE", pMedia, true )
end
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: Show a plugin prepared citation
Thanks Mike!
Re: Show a plugin prepared citation
It should work, but it doesn't and I don't know why.
The code is:
-- Set Source Date to Media Date
local dDate = fhGetValueAsDate(fhGetItemPtr(pSource,'~.~DT-DATUM'))
local pDate = fhNewItemPtr()
pDate:MoveTo(pMedia,'~._DATE')
if pDate:IsNull() then
pDate = fhCreateItem( "_DATE", pMedia, true )
end
fhSetValueAsDate(pDate,dDate)
dDate is correct
pDate is created (I think)
but the date is not set in the media record
Wat am I doing wrong?
The code is:
-- Set Source Date to Media Date
local dDate = fhGetValueAsDate(fhGetItemPtr(pSource,'~.~DT-DATUM'))
local pDate = fhNewItemPtr()
pDate:MoveTo(pMedia,'~._DATE')
if pDate:IsNull() then
pDate = fhCreateItem( "_DATE", pMedia, true )
end
fhSetValueAsDate(pDate,dDate)
dDate is correct
pDate is created (I think)
but the date is not set in the media record
Wat am I doing wrong?
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Show a plugin prepared citation
it is working for OK me in a little test script.
Change the last line to local isOK = fhSetValueAsDate(pDate,dDate) to check the date is set Ok.
and if necessary put a dummy statement after it like local zz=0 so you can step onto that.
In debug mode step through those statements one by one and check the values of each variable.
e.g.
At statement local zz=0 it should show:
dDate date local 1 May 2000
pDate item local Date: 1 May 2000
isOK local true
You can also check which records pSource and Media are pointing at.
Change the last line to local isOK = fhSetValueAsDate(pDate,dDate) to check the date is set Ok.
and if necessary put a dummy statement after it like local zz=0 so you can step onto that.
In debug mode step through those statements one by one and check the values of each variable.
e.g.
At statement local zz=0 it should show:
dDate date local 1 May 2000
pDate item local Date: 1 May 2000
isOK local true
You can also check which records pSource and Media are pointing at.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: Show a plugin prepared citation
The results of the debug:
pMedia: Link to Media record (Boelhouwer, Margrieta - 1917-08-15 Nieuw Helvoet - SAVP O-21; 133)
dDate: 15 August 1917
pDate: (null) - also after MoveTo(pMedia,'~._DATE') - also after pDate = fhCreateItem('_DATE', pMedia)
isOK: false - after local isOK = fhSetValueAsDate(pDate,dDate)
I have attached the plugin, I hope that helps to diagnose what's happening. [Edit to add: Superseded by a later version]
pMedia: Link to Media record (Boelhouwer, Margrieta - 1917-08-15 Nieuw Helvoet - SAVP O-21; 133)
dDate: 15 August 1917
pDate: (null) - also after MoveTo(pMedia,'~._DATE') - also after pDate = fhCreateItem('_DATE', pMedia)
isOK: false - after local isOK = fhSetValueAsDate(pDate,dDate)
I have attached the plugin, I hope that helps to diagnose what's happening. [Edit to add: Superseded by a later version]
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Show a plugin prepared citation
It is a matter of being consistent ~ just like most things in FH.
pMedia is pointing at SOUR.OBJE which is a field inside the Source record.
So you correctly use MoveTo(pMedia,'~>FILE') to follow the pointer to its linked Media record FILE tag.
So you must do the same for _DATE and _KEYS
i.e. MoveTo(pMedia,'~>_DATE') and MoveTo(pMedia,'~>_KEYS')
BUT fhCreateItem('_DATE', pMedia) won't work because that is trying to create SOUR.OBJE._DATE
So it would be much neater if initially, you use:
local pMedia = fhGetItemPtr(pSource,'~.OBJE>') so that pMedia points to the Media record.
Then you need to use MoveTo(pMedia,'~.FILE') and the _DATE and _KEYS code will work without changes.
BTW: I strongly suggest you use the same technique for FILE and TITL as I suggested for _DATE and _KEYS just in case they don't exist by default. You could have a little function that is given the parent pointer and the tag and returns the pointer to the tag.
That will even work for _KEYS by just using the else code section (could test for oldKeys == "" if you like).
pMedia is pointing at SOUR.OBJE which is a field inside the Source record.
So you correctly use MoveTo(pMedia,'~>FILE') to follow the pointer to its linked Media record FILE tag.
So you must do the same for _DATE and _KEYS
i.e. MoveTo(pMedia,'~>_DATE') and MoveTo(pMedia,'~>_KEYS')
BUT fhCreateItem('_DATE', pMedia) won't work because that is trying to create SOUR.OBJE._DATE
So it would be much neater if initially, you use:
local pMedia = fhGetItemPtr(pSource,'~.OBJE>') so that pMedia points to the Media record.
Then you need to use MoveTo(pMedia,'~.FILE') and the _DATE and _KEYS code will work without changes.
BTW: I strongly suggest you use the same technique for FILE and TITL as I suggested for _DATE and _KEYS just in case they don't exist by default. You could have a little function that is given the parent pointer and the tag and returns the pointer to the tag.
Code: Select all
local function MakeTag(pParent,sTag)
-- local pNew = fhNewItemPtr()
-- pNew:MoveTo(pParent,'~.'..sTag)
local ptrNew = fhGetItemPtr(pParent,'~.'..sTag) -- Slightly more efficient
if pNew:IsNull() then
pNew = fhCreateItem(sTag, pParent)
end
return pNew:Clone()
end
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: Show a plugin prepared citation
I did as you wrote (at least I think I did ), but I can't get it working
The code now looks like:
pMedia = fhGetItemPtr(pSource,'~.OBJE>')
pFile:MoveTo(pMedia,'~.FILE')
-- Set Media Title to Source Title (= filename)
pTitle = makeTag(pFile,'TITL')
fhSetValueAsText(pTitle,sTitle)
-- Set Source Date to Media Date
local dDate = fhGetValueAsDate(fhGetItemPtr(pSource,'~.~DT-DATUM'))
pDate = makeTag(pFile,'DATE')
fhSetValueAsDate(pDate,dDate)
-- Set Media keyword to Source Type
local sType = fhGetValueAsText(fhGetItemPtr(pSource, '~.~EN-TYPE'))
local sTemplate = fhGetValueAsText(fhGetItemPtr(pSource, '~._SRCT>NAME'))
pKeys = makeTag(pFile,'KEYS')
local oldKeys = fhGetValueAsText(pKeys)
if oldKeys == '' then
fhSetValueAsText(pKeys,sType)
else
if not string.find(oldKeys, sType) then
oldKeys = oldKeys .. ', ' .. sType
end
if not string.find(oldKeys, sTemplate) then
oldKeys = oldKeys .. ', ' .. sTemplate
end
fhSetValueAsText(pKeys,oldKeys)
end
Wat did I do wrong?
The code now looks like:
pMedia = fhGetItemPtr(pSource,'~.OBJE>')
pFile:MoveTo(pMedia,'~.FILE')
-- Set Media Title to Source Title (= filename)
pTitle = makeTag(pFile,'TITL')
fhSetValueAsText(pTitle,sTitle)
-- Set Source Date to Media Date
local dDate = fhGetValueAsDate(fhGetItemPtr(pSource,'~.~DT-DATUM'))
pDate = makeTag(pFile,'DATE')
fhSetValueAsDate(pDate,dDate)
-- Set Media keyword to Source Type
local sType = fhGetValueAsText(fhGetItemPtr(pSource, '~.~EN-TYPE'))
local sTemplate = fhGetValueAsText(fhGetItemPtr(pSource, '~._SRCT>NAME'))
pKeys = makeTag(pFile,'KEYS')
local oldKeys = fhGetValueAsText(pKeys)
if oldKeys == '' then
fhSetValueAsText(pKeys,sType)
else
if not string.find(oldKeys, sType) then
oldKeys = oldKeys .. ', ' .. sType
end
if not string.find(oldKeys, sTemplate) then
oldKeys = oldKeys .. ', ' .. sTemplate
end
fhSetValueAsText(pKeys,oldKeys)
end
Wat did I do wrong?
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Show a plugin prepared citation
I think you must be getting tired.
pDate = makeTag(pFile,'DATE') should be pDate = makeTag(pMedia,'_DATE') and ditto for _KEYS
i.e. both parent pointer and tag were wrong.
If you step through the code in debug it would soon become clearer what steps do not work.
pDate = makeTag(pFile,'DATE') should be pDate = makeTag(pMedia,'_DATE') and ditto for _KEYS
i.e. both parent pointer and tag were wrong.
If you step through the code in debug it would soon become clearer what steps do not work.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry