PDA

View Full Version : How-to: Creating a module out of an Excel/Calc table



Zarestia
June 4th, 2021, 14:00
Yesterday, I read a post in the Fantasy Grounds College discord asking how to easily create items in Fantasy Grounds as that person created an Excel table with around 800 entries.
Today I want to show you how I created a module containing 801 items in about half an hour (had to fix that table a bit before starting). This works with Excel, Libre Calc, etc. and is best suited for anything that works logically in a table format (items, feats, spells [automation is another topic], etc.) and you have hundreds of, it's scalable.

For this example i use D&D 5e and gemstones as items. My workflow for sure has some things which can be made better but it works for me as this is all self-thaught.

Step 1: Inspect the data structure of the entries you want to create

Create a test campaign, DND 5e, no extensions.
Create an item with and hit /export in the chat when you're done.
Fill out your information and tick the data entries which you want to export.
https://i.imgur.com/90iEbLW.jpg
Navigate to your modules folder (default: %appdata%\SmiteWorks\Fantasy Grounds\modules) and unzip the created module.
Open the db.xml in an IDE or somehting like Notepad++.
We can see this code:

<?xml version="1.0" encoding="utf-8"?>
<root version="4.1" dataversion="20210302" release="8.1|CoreRPG:4.1">
<item>
<id-00001>
<ac type="number">0</ac>
<bonus type="number">0</bonus>
<cost type="string">10 gp</cost>
<description type="formattedtext">
<p />
</description>
<isidentified type="number">0</isidentified>
<locked type="number">1</locked>
<name type="string">Azurite</name>
<nonid_name type="string">Blue Gemstone</nonid_name>
<subtype type="string">Gemstones (10 Gp)</subtype>
<type type="string">Treasure</type>
<weight type="number">0.01</weight>
</id-00001>
</item>
<library>
<dataentrymodule static="true">
<categoryname type="string">Supplement</categoryname>
<name type="string">dataentrymodule</name>
<entries>
<item static="true">
<librarylink type="windowreference">
<class>reference_list</class>
<recordname>..</recordname>
</librarylink>
<name type="string">Items</name>
<recordtype type="string">item</recordtype>
</item>
</entries>
</dataentrymodule>
</library>
</root>
We can omit the tags for ac, bonus and description as we don't need them for our items in this case.

We need values for the following things:
Name
Unidentified Name
Cost
Locked
Type
Subtype
Weight



Step 2: Prepare our table

I did some chaining and linking in the table I got from the user to the values we need.
https://i.imgur.com/JSblAQw.jpg
I created a new FGU Builder table with all the XML start and end tags we need. (isidentified is missing in the screenshot as I did that in the aftermath.)
https://i.imgur.com/fOqtTJj.jpg
I then chained those together and linked them to the data table to get the whole XML data for one item.
This is the end result:
https://i.imgur.com/p75UooY.jpg


Step 3: XML editing with Regex

I copy our end result to a new document in Notepad++
As every item is only one row we need to split those up. We do this for every tag.
https://i.imgur.com/C2fklYV.jpg
As this deleted all our end tags we need to create them anew - no problem with Regex.
https://i.imgur.com/TS49PCt.jpg
Lastly, we need to create an ID for every item. For Notepad++ I've written a short python script which can be executed with the python plugin. Everything starting in a new line with 0 gets replaced with IDs.

i=-1

def increment(match):
global i
i=i+1
return "</id-"+str(i)+"><id-"+str(i+1)+">"

editor.rereplace('^(?=0)', increment)
We need to create new lines, before every name tag.
https://i.imgur.com/gMRB0YX.jpg
We need to replace those lines with a starting 0, I make them "0abc" because that would be unique for later deletion
https://i.imgur.com/45y199x.jpg
We now execute our little script and voilá, we got IDs wrapped around every item, need to clear up the first and last item.
Lastly, delete "0abc" with a simple replace as none.


Step 4: Wrap it up in a module

Grab the extracted db.xml again and look for the code before the actual data.

<?xml version="1.0" encoding="utf-8"?>
<root version="4.1" dataversion="20210302" release="8.1|CoreRPG:4.1">
<item>
and

</item>
<library>
<dataentrymodule static="true">
<categoryname type="string">Supplement</categoryname>
<name type="string">dataentrymodule</name>
<entries>
<item static="true">
<librarylink type="windowreference">
<class>reference_list</class>
<recordname>..</recordname>
</librarylink>
<name type="string">Items</name>
<recordtype type="string">item</recordtype>
</item>
</entries>
</dataentrymodule>
</library>
</root>
Copy your create data into the db.xml bewteen those two parts, overwriting the one old item. Save the file.
Zip the definition.xml and db.xml and rename the module however you want, it needs to have the ending .mod
Load it up in Fantasy Grounds.


I hope this helps someone out when entering many data entries into Fanatsy Grounds. If there are questions or improvement suggestions, ask away. You don't need excel or calc data, I used nearly the same XML workflow for creating 1k spells for my D&D 3.5 Spell Compendium module, just had to copy every spell into Notepad++. Still way faster than typing 1.000 spells manually into Fantasy Grounds. This whole things might seem much but once you've done it, it is rather easy.

superteddy57
June 4th, 2021, 14:07
Good stuff!

ndjester
June 4th, 2021, 15:23
Thanks for the help with my gem items!!! :)

LordEntrails
June 7th, 2021, 03:27
Ooh, interesting. This looks very useful. Bookmarked it for later comprehension.

As for importing excel to FG tables, there is an extension that already does this. Or at least their used to be... I'm not sure what one of these I used in the past, but I used one of them with my 44 trillion dungeon room descriptions module.

Check these out, it's got to be one of these;
https://www.fantasygrounds.com/forums/showthread.php?49930-CSV-Table-Importer-MK
https://www.fantasygrounds.com/forums/showthread.php?40812-5E-Table-Importer