Skip to content

Commit

Permalink
+ script to collect variables metadata, fix #116
Browse files Browse the repository at this point in the history
  • Loading branch information
berteh committed Jan 29, 2019
1 parent 178f9ed commit ac44f83
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ A full example to generate Monsters Game Cards based on [Dungeon World](http://w

[![Illustration: Example card deck of monsters, by Dustin Andrew](pic/MonsterCards_partial.png)](https://github.com/berteh/ScribusGenerator/raw/master/example/MonsterCards/MonsterCards_partial.pdf)

### Changes in NEXT-RECORD syntax

Please note Scribus Generator v2.8 (from January 2019) changed the syntax of the ["Next Record" feature](https://github.com/berteh/ScribusGenerator#multiple-records-on-a-single-page)
to a less confusing name, as per [suggestion #118](https://github.com/berteh/ScribusGenerator/issues/118)
Expand Down Expand Up @@ -340,6 +341,11 @@ toggle unaligned output with the ```\a``` switch, activate a comma as a separato

You can use ```sqlite3 -csv``` in command line or ```.mode csv``` in sqlite's interactive shell

#### Scripts

Various scripts are available in the ``utils`` folder to facilitate your use of Scribus Generator.
Check out the [related README](https://github.com/berteh/ScribusGenerator/blob/master/utils/README.md) !

Known Issues
-------
### Mac OSX troubleshooting
Expand Down
35 changes: 35 additions & 0 deletions utils/CollectSGVarsFromScribus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

## CSV list for Scribus Generator
## Finds all objects with '%VAR' and lists in a csv (Filename, Variable and type: text/image
## CSV is stored in same folder with the suffix 'Elements'

## contribution from jvr14115, https://github.com/berteh/ScribusGenerator/issues/116
## run from within Scribus > Script > run Script

import os
import re
import scribus

Edoc = scribus.getDocName()
Edoc = Edoc.replace('.sla', '')
file_name = Edoc + 'Elements.csv'
Edoc = Edoc.replace('Elements.csv', '')
Edoc = re.search(r'(.*)/(.*)', Edoc).group(2)
f = open(file_name, 'w+')
f.write('Template,Element,ElementType')
f.write('\n')
objL = scribus.getAllObjects()
for obj in objL:
objT = scribus.getObjectType(obj)
Evar = ''
if objT == 'ImageFrame':
Etype = 'image'
Evar = scribus.getImageFile(obj)
if objT == 'TextFrame':
Etype = 'text'
Evar = scribus.getAllText(obj)
if '%VAR_' in Evar:
Evar = re.sub('^[^%VAR_]*%VAR_', '', Evar)
Evar = Evar[:-1]
f.write(Edoc + ';"' + Evar + '";' + Etype + '\n')
f.close
13 changes: 13 additions & 0 deletions utils/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Various Scripts
===========

Collect variables in template
-----------

To find all objects with '%VAR' and lists them in a csv (Filename, Variable and type: text/image),
[jvr14115](https://github.com/berteh/ScribusGenerator/issues/116) provided a script you need
to run from within Scribus ``> Script > run Script``, pick ``utils/CollectSGVarsFromScribus.py``

Resulting CSV is stored in same folder with the suffix 'Elements'.

Improvement suggestions are welcome to handle multiple %VAR_%'s in single text frame.



Fixes to retro-compatibility issues
-----------

Expand Down

0 comments on commit ac44f83

Please sign in to comment.