PDA

View Full Version : CSV Table Importer MK



mattekure
July 9th, 2019, 14:23
This extension allows you to import the contents of a Comma Separated Values(CSV) file into either:

Formatted text control. Importing the CSV into a formatted text control will create it as a formatted table.
Rollable table. Importing into a blank rollable table entry will generate all of the rows and columns for the rollable table.



Note: This extension is based on the CSV Table Paster extension by lokiare which is available here: https://www.fantasygrounds.com/forums/showthread.php?40821-CSV-Table-Paster-Community-Extension-Early-Access-release Much thanks to him.


To use:
Outside of FG

Open your CSV file in a text editor such as notepad.
Copy the contents of the CSV to the clipboard using CTRL+A, CTRL+C or equivalent.


Within FG

Click on the dark green hammer and gear icon at the top right of the desktop. This will open the import window.
Open the window that contains the formatted text field you want to import the CSV into. If you are importing a rollable table, just open a blank table entry.
If you are importing into a formatted text field, type "#table#" without quotes on a new line where you want the table to appear. Close the entry, then re-open it.
Click on the "Convert Clipboard" button on the import window


Demo Video:
https://youtu.be/PIiZonTjGh8

Changes from original version

Should work with all CoreRPG and 5e ruleset formatted text fields. Can be easily extended to support other rulesets as well.
changed the background of the instruction text to make it more readable.
replaced CSV parsing code so that it handles quoted strings properly. To produce a quote character " into an entry, it must be escaped by an additional ".

So this CSV 27851
Will produce this output 27852

Supported Rulesets: CoreRPG, 5E, 2E, PFRPG, PFRPG2, Savage worlds

Version notes
v1.0 initial release
v1.1 Added support for the following rulesets 2E, PFRPG, PFRPG2, SavageWorlds
v1.2 Added the ability to skip leading and trailing spaces.
v1.3 Added the option to select other delimiters. Default is comma. Can now select pipe "|", semi-colon or colon as the delimiter
v1.3a Update for compatibility with Unity.
v1.3b Minor update for compatibility with some themes.
v1.4 fixed some minor console errors.
v1.5 re-fixed the console errors, added ability to import on char sheet abilities, feats, skills, traits, etc.
v1.6 added support for Better Menu extension

lokiare
July 9th, 2019, 20:30
This extension uses code from my extension with permission from me to use it.

Bidmaron
July 10th, 2019, 04:30
Here's how you can do it:

In your onInit routine, place the following code:

OptionsManager.registerOption2("GENPUNC", false, "option_header_game", "option_label_GENPUNC", "option_entry_stringer",
{ baselabel = "option_val_comma", baseval = ",", default = "," });

'GENPUNC' or whatever you want to use instead of that will be the reference you later use to get the value of the setting.
The false parameter tells the option manager it is an option that should be stored in the campaign database (true causes it to be stored in the campaign registry).
'option_header_game' tells the Options Manager to put the setting into the games settings area (see the strings\strings_utility.xml file for the constants you can use to control where the option appears)
'option_label_GENPUNC' tells the Options Manager to look for this string resource for the label you want assigned on the options manager. It looks like this:


<string name="option_label_GENPUNC">Generators: Punctuation to separate items in a series</string>

'option_entry_stringer' is the windowless you want to use to handle the interaction with the user. There is not currently a built-in routine to handle what you are looking for, but this code below is fully tested and will handle a string option setting that is free-form:


<windowclass name="option_entry_stringer">
<margins control="0,0,0,2" />
<script>
local sOptionKey = nil;
local sDefaultVal = "";
local enable_update = true;

function setLabel(sLabel)
label.setValue(sLabel);
end

function setReadOnly(bValue)
stringer.setReadOnly(bValue);
end

function initialize(sKey, aCustom)
sOptionKey = sKey;

if sOptionKey then
if aCustom then
sDefaultVal = aCustom.baseval or "";
end

enable_update = false;
local sValue = OptionsManager.getOption(sOptionKey);
stringer.setValue(sValue);
enable_update = true;
end
end

function onHover(bOnWindow)
if bOnWindow then
setFrame("rowshade");
else
setFrame(nil);
end
end

function onValueChanged()
if enable_update and sOptionKey then
local sValue = stringer.getValue();
OptionsManager.setOption(sOptionKey, sValue);
end
end
</script>


The last parameter is an array passed to control behavior. Since this is a freeform string, I don't set up a series of labels, but you could conceivably setup a series of "|" (pipe) delimited string resource names of labels to use. (or lablesraw if you don't want resources).
What I have up there will make the default be a comma, and the 'option_val_comma' is a string resource you set up in your xml file like this:


<string name="option_val_comma">,</string>


Where you need to get the current CSV setting, you would do something like this:


local sSeparator=OptionsManager.getOption("GENPUNC");

If you needed to (not sure why you would need to), you could use the Options Manager to register a callback to your code if the value of your setting changes. (see the Options Manager registerCallback and unregisterCallback routines).

mattekure
July 10th, 2019, 11:54
That was amazing Bidmaron, thanks. Excellent documentation

Bidmaron
July 10th, 2019, 11:56
You are very welcome sir

Andraax
August 4th, 2019, 20:42
Bug: If there is whitespace between the comma and a following " then it ignores the quotes.

mattekure
August 4th, 2019, 21:48
Bug: If there is whitespace between the comma and a following " then it ignores the quotes.

This isnt actually a bug as this is not following the CSV standard. https://tools.ietf.org/html/rfc4180

CSV fields are separated by a comma and either begin with a double quote, or not. If a CSV field does not begin with a double quote, it cannot contain quote characters within it. In your example, the field is beginning with a space, and so the entire field should not contain any quote characters. If a CSV field does begin with a double quote, it can contain a quote symbol by escaping it with another double quote. For example. value1,"value2""stillvalue2",value3 where the middle term evaluates to value2"stillvalue2

Andraax
August 5th, 2019, 00:15
You seem to have skipped the part that says:


While there are various specifications and implementations for the CSV format (for ex. [4], [5], [6] and [7]), there is no formal specification in existence, which allows for a wide variety of interpretations of CSV files. This section documents the format that seems to be followed by most implementations:

So, while this documents the most common format, it is not a formal specification.

LordEntrails
August 5th, 2019, 00:41
So, while this documents the most common format, it is not a formal specification.
Well, I guess one way to think of it is if the author of an extension wants it to work one way and its working that way, then it's working correctly.

Of course someone can always ask for an extension to be coded differently, but that's different than saying it not working correctly.

mattekure
August 5th, 2019, 01:00
You seem to have skipped the part that says:



So, while this documents the most common format, it is not a formal specification.

I did not in fact skip that part. Yes, it is not a formal specification but attempting to account for every possible implementation and undocumented version of the file format is not really productive. So I wrote to the most common format.

mattekure
August 5th, 2019, 03:42
Version 1.2 uploaded. Added the ability to skip leading and trailing spaces.

Andraax
August 5th, 2019, 12:09
Version 1.2 uploaded. Added the ability to skip leading and trailing spaces.

Thank you.

mattekure
August 5th, 2019, 14:27
Update to version 1.3. Thanks to the code provided by Bidmaron I have added the ability to select other delimiters. The default is a comma, but in the options you can now select between a comma ",",pipe "|", semi-colon ";", and colon ":".

Bidmaron
August 5th, 2019, 23:07
Glad to help, mattekure! And I think it's remarkable you did this mod.

mattekure
August 6th, 2019, 00:03
Glad to help, mattekure! And I think it's remarkable you did this mod.

Thank you. To give credit where it is really due, the bulk of the extension was already built when I decided to tweak it. I've tried to add a little bit to it and fix up a few things, but I do greatly appreciate the original work done by Lokiare.

deer_buster
September 14th, 2019, 04:39
Small bug, strings.xml needs to have a "root" node, not a "base" node.

lokiare
September 15th, 2019, 15:29
Small bug, strings.xml needs to have a "root" node, not a "base" node.

Fantasy Grounds Classic can use either, but Fantasy Grounds Unity is stricter on XML interpretation and must have a 'root' node instead of a 'base' node.

mattekure
September 15th, 2019, 15:51
v1.3a uploaded. changes the xml to a root node for compatibility with Unity.

Thanks for the report!

brunocalado
November 28th, 2019, 17:08
Can you change your loadorder do <55?

Can't replace your button in my theme.

mattekure
November 28th, 2019, 17:27
I'll have to test it, but I can certainly try. Here is a version with the load order set to 54.

brunocalado
November 28th, 2019, 17:28
I'll have to test it, but I can certainly try. Here is a version with the load order set to 54.

Thank you. You're awesome.

mattekure
November 28th, 2019, 17:34
let me know the results, if it works fine, I'll go ahead and post the update on my extensions thread.

brunocalado
November 28th, 2019, 17:40
let me know the results, if it works fine, I'll go ahead and post the update on my extensions thread.

30536

Asterionaisien
February 23rd, 2020, 15:44
I would like to thank you and Lokiare for this great extension, it has really helped me a lot in converting a ruleset for my use. Works really fine, great work!

moongleam
April 3rd, 2020, 00:23
Hi guys.
I am total noob here and I have need for this tool.
But here what happens when I start this wonderful extension. No sure but I think it's not working becouse of it.

[4/3/2020 1:16:36 AM] [WARNING] window: Anchored static height ignored for control (csvtp_label) in windowclass (CSVTPWindow)
[4/3/2020 1:16:36 AM] [WARNING] window: Anchored static height ignored for control (csvtp_label) in windowclass (CSVTPWindow)

Ah yes. I have FGU.

Thanks to any good soul that can help me here.

mattekure
April 3rd, 2020, 00:57
Hi guys.
I am total noob here and I have need for this tool.
But here what happens when I start this wonderful extension. No sure but I think it's not working becouse of it.

[4/3/2020 1:16:36 AM] [WARNING] window: Anchored static height ignored for control (csvtp_label) in windowclass (CSVTPWindow)
[4/3/2020 1:16:36 AM] [WARNING] window: Anchored static height ignored for control (csvtp_label) in windowclass (CSVTPWindow)

Ah yes. I have FGU.

Thanks to any good soul that can help me here.

Thanks for the report, I will try to put out an update that fixes those. Meanwhile, those are just minor warning messages that dont affect the functioning of the CSV import. You can safely ignore them until I put out the update.

mattekure
April 3rd, 2020, 02:03
v1.4 posted. Fixed the console errors for both classic and unity.

moongleam
April 3rd, 2020, 14:48
Wonderful job. Everything works perfect.
I have also tried to copy table where I shouldn't but it's my mistake.

Thank you so much mattekure for making our lives easier, you really made my day better and my work with FG more comfortable.

PootyPooPoo
April 4th, 2020, 22:52
Hey mattekure,

Thanks for creating this tool, it has been very useful. Unfortunately, I am still receiving errors even with v1.4.

33073

Using in a 5e campaign on FGC.

mattekure
April 5th, 2020, 05:10
Hey mattekure,

Thanks for creating this tool, it has been very useful. Unfortunately, I am still receiving errors even with v1.4.

33073

Using in a 5e campaign on FGC.

Could you try again with all other extensions removed. I am not seeing this with a new 5e campaign.

PootyPooPoo
April 5th, 2020, 17:14
I removed all other extensions as you suggested. I also attempted in a newly created campaign, and deleted and re-downloaded the v1.4 file and replaced. If no other users are experiencing issues, I will assume this is something on my end only. I hope the provided images help.

I found that the same console errors shown in my previous post still occur every time the "CSV" button is clicked. Is that button still supposed to show as the blue hammer icon as it was in previous versions? With additional testing, I found the following:

1. Unable to import tables to a "Skills", "Feats", "Features", or "Traits" link sheet in a character sheet. I was able to do this in previous versions without issue.
2. Tables do successfully import to link sheets for "Items" and "Story".

33140
33141
33142
33143
33144

mattekure
April 5th, 2020, 17:18
Hmm, ok. I'll take a closer look and see if I cant recreate this and fix it.

thanks

mattekure
April 6th, 2020, 01:11
I removed all other extensions as you suggested. I also attempted in a newly created campaign, and deleted and re-downloaded the v1.4 file and replaced. If no other users are experiencing issues, I will assume this is something on my end only. I hope the provided images help.

I found that the same console errors shown in my previous post still occur every time the "CSV" button is clicked. Is that button still supposed to show as the blue hammer icon as it was in previous versions? With additional testing, I found the following:

1. Unable to import tables to a "Skills", "Feats", "Features", or "Traits" link sheet in a character sheet. I was able to do this in previous versions without issue.
2. Tables do successfully import to link sheets for "Items" and "Story".

33140
33141
33142
33143
33144

Ok, update 1.5 is uploaded.

For the console errors, I can only plead temporary stupidity. The 1.4 I uploaded had zipped up the wrong set of files. it zipped up a different test set. This should have no console errors *hopefully*

I did find why the entries from a char sheet were not working and added them.

PootyPooPoo
April 6th, 2020, 02:00
Thanks mattekure, v1.5 seems to have everything working as intended! Awesome work, thanks for the rapid fix!

orien45
April 28th, 2020, 21:23
Quick note, the Demo video on the OP seems to be no longer there. Just letting you know for clean up or correction purposes.

mattekure
April 28th, 2020, 22:55
Quick note, the Demo video on the OP seems to be no longer there. Just letting you know for clean up or correction purposes.

I dont know how that happened, somehow Youtube deleted it. I have re-uplaoded the video and it should be available now. I have changed the link on the first post.

orien45
April 29th, 2020, 12:15
Thank you for all the great stuff, btw!

MadNomadGM
May 9th, 2020, 18:15
Great work by you and the legacy mod creator! I'm building some complex table systems and this will help a lot.


One suggestion for the future, if you are still working on this at all. It would be really cool if entries in the tables could reference other files instead of just text.

For example, when creating a table directly in FG you can drag an npc or an item or any object into the row and when that roll is done it will paste the link to that nps, or object, etc in the chat, story, encounter, etc.

I imagine that each of those items, when dragged into the table, are essentially links. And Maybe if you knew the name and formatting of those links it would be possible to enter those in the .csv file and covert them to links on import?

Just an idea.

mattekure
May 24th, 2020, 01:10
v1.6 uploaded. added support for BetterMenu extension

roninkelt
November 4th, 2020, 22:23
I'm having trouble getting the extension to work consistently. For the last week or so, I've had to restart FGC to get tables to show up.

Tried doing a bit of debugging by turning off all other extensions with no change in behavior. Not seeing any output to the console so is difficult to go any farther. Any suggestions?

mattekure
November 4th, 2020, 23:56
I'm having trouble getting the extension to work consistently. For the last week or so, I've had to restart FGC to get tables to show up.

Tried doing a bit of debugging by turning off all other extensions with no change in behavior. Not seeing any output to the console so is difficult to go any farther. Any suggestions?

The key to getting the tables to import consistently is to ensure that the window being imported into is the most recently opened window.

In general, the process is

Open the CSV Importer window
Open the window where you want to input text and put in the #table#
Go to your CSV file, copy all of the contents
Return to FG
Close and then Reopen the window where you want to import the data
click the import button on the CSV importer window.


I know it seems a bit weird, but it is important to close and reopen the target window just before clicking the import button on the CSV importer window. This is the only way that the extension knows which window to target for the import.

roninkelt
November 5th, 2020, 00:22
ah, important steps I didn't know about. Will follow your procedure and let you know how it goes. Thank you.

Coveny
November 10th, 2020, 17:24
Is it possible to import multiple tables for random encounters that references creatures from the SRD?

So like parent table
1 = 1d2 Orcs (child table)
2 = 1d3 Goblins (child table)
3 = 1d4 Kobolds (child table)

Even if I can't do the parent table being able to do multiple tables from a csv file would be lovely.

mattekure
November 10th, 2020, 17:43
Is it possible to import multiple tables for random encounters that references creatures from the SRD?

So like parent table
1 = 1d2 Orcs (child table)
2 = 1d3 Goblins (child table)
3 = 1d4 Kobolds (child table)

Even if I can't do the parent table being able to do multiple tables from a csv file would be lovely.

No importing multiple tables from a single CSV file is not possible. there is no provision in the CSV file format standard that would allow the definition of multiple tables that way.

roninkelt
November 12th, 2020, 00:52
I think you'd have to create the child tables first, then the parent table and drop the children into the parent to get proper linking.

roninkelt
November 17th, 2020, 20:19
Now having trouble importing rollable tables. Same difficulty as before, except I'm following the steps above as applicable. Is there some trick to doing this?

Getting the following messages in the console:

Runtime Notice: s'Opening window table with path tables.id-00001'
Runtime Notice: s'Opening window masterindex with path tables'
Runtime Notice: s'Window has closed'
Runtime Notice: s'Window has opened'
Runtime Notice: s'Couldn't get the node for the window.'
Runtime Notice: s'Window has closed'
Runtime Notice: s'Window has opened'
Runtime Notice: s'NodePath:tables.id-00001'
Runtime Notice: s'Class:table'
Script Error: [string "scripts/CSVTablePaster.lua"]:295: attempt to perform arithmetic on local 'startp' (a nil value)

mattekure
November 17th, 2020, 21:55
I'm not seeing this. My general process is to:


Open the CSV Importer Window
Open the Table records window.
Copy the CSV data
In the Table Records window, click on the green + to create a new rollable table
click the Convert Clipboard button.


That correctly creates a table with my test CSV files. If you are still having trouble, could you try posting a copy of a CSV file and I'll take a look at it.

roninkelt
November 18th, 2020, 01:58
No dice, I'm completely unable to paste a rollable table. I've turned off all other extensions, but that hasn't made any difference.

error messages in the console

Runtime Notice: s'Window has closed'
Runtime Notice: s'Window has opened'
Runtime Notice: s'NodePath:tables.id-00002'
Runtime Notice: s'Class:table'
Script Error: [string "scripts/CSVTablePaster.lua"]:295: attempt to perform arithmetic on local 'startp' (a nil value)

Here is some sample data that I'm trying to paste:

Achievement,"To overcome obstacles and succeed; to become the best"
Acquisition,"To obtain possessions/wealth"
Adoration,"To be cherished, admired, and wanted by others"
Balance/Peace,To bring all things into harmony and equilibrium
Beneficence,"To protect the helpless, heal the sick, feed the hungry, etc."
Chaos,"To disrupt, to cause confusion and discord"
Competition,"To seek out or create rule,based win/lose scenarios; to defeat others in
contests"
Conflict,"To seek out or create rivalry, fighting, or animosity"
Conquest,"To conquer other peoples, to bring them into one’s own culture/rule"
Corruption,"To despoil, ruin, humiliate, or make depraved"
Creation,"To build or make new, such as art, culture, invention, design,etc."
Destruction,"To annihilate, exterminate, and unmake"
Discovery/Adventure,"To explore, uncover mysteries, and pioneer"

mattekure
November 18th, 2020, 13:22
No dice, I'm completely unable to paste a rollable table. I've turned off all other extensions, but that hasn't made any difference.

error messages in the console

Runtime Notice: s'Window has closed'
Runtime Notice: s'Window has opened'
Runtime Notice: s'NodePath:tables.id-00002'
Runtime Notice: s'Class:table'
Script Error: [string "scripts/CSVTablePaster.lua"]:295: attempt to perform arithmetic on local 'startp' (a nil value)

Here is some sample data that I'm trying to paste:

Achievement,"To overcome obstacles and succeed; to become the best"
Acquisition,"To obtain possessions/wealth"
Adoration,"To be cherished, admired, and wanted by others"
Balance/Peace,To bring all things into harmony and equilibrium
Beneficence,"To protect the helpless, heal the sick, feed the hungry, etc."
Chaos,"To disrupt, to cause confusion and discord"
Competition,"To seek out or create rule,based win/lose scenarios; to defeat others in
contests"
Conflict,"To seek out or create rivalry, fighting, or animosity"
Conquest,"To conquer other peoples, to bring them into one’s own culture/rule"
Corruption,"To despoil, ruin, humiliate, or make depraved"
Creation,"To build or make new, such as art, culture, invention, design,etc."
Destruction,"To annihilate, exterminate, and unmake"
Discovery/Adventure,"To explore, uncover mysteries, and pioneer"

I am still unable recreate the error. when I import using your text it works fine on my machine. For now, I would recommend using the new table importer that is built in to FG. It handles CSV text just fine and largely replaces this extension (for rollable tables). I will take a look, but I may go ahead and retire this extension since the functionality is now built in.

For debugging purposes:
What client are you using (classic/unity?)
What ruleset?
What version of the extension? It will show in the chat on startup, current version is 1.6.

roninkelt
November 18th, 2020, 18:15
I didn't realize there was a built in csv import capability. Will have to dig into that.

For debugging - I'm using FG Classic in the 5e ruleset and the version of the extension is reported as CoreRPG - CSV Table Importer MK 1.6

roninkelt
November 19th, 2020, 00:10
I think I may have figured it out - I was using an older version of the 5e several other rulesets. Apparently, FG prefers the unzipped rulesets over the .pak files. There were several unzipped in my ruleset directory from experimenting with extensions. Removed these and all is well now.

mattekure
November 19th, 2020, 02:26
Ah, awesome. glad to hear it.

Milmoor
March 1st, 2021, 19:57
Thanks, that saves me some awful editing. Unfortunately this does not work with the Worldbuilder (https://www.fantasygrounds.com/forums/showthread.php?54284-Player-Agency-Extension). Solved it by using a link to a story. So I'm good for now. Mainly posting this so others don't have to find out this doesn't work.