site_graphlogo
  -   Terms of Use and Privacy
Source Code
rss
site_graphlogo
  -   Terms of Use and Privacy
Source Code
rss

Source Code | Vym Export

This program exports Vym diagrams to Cruft Buster trees, Word Docs, and PDFs.

#!/usr/bin/python3
#coding=utf-8
#Vym EXport
#Copyright (C) 2020 Tributary Software

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#or view the license here: https://tributarysoftware.com/gpl2.txt
import sys
from lxml import etree
from pathlib import Path
from docx import Document
from docx.shared import Inches

try:
   typedoc=sys.argv[1]
   source=sys.argv[2]
   target=sys.argv[3]
   title=sys.argv[4]
   imagesrt=sys.argv[5]
except:
   print('Error.  Need five arguments: <typedoc> <source> <target> <title> <imagesrt>')
home = str(Path.home())
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(source,parser)
root=tree.getroot()
document = Document()
document.add_heading(title, 0)
for node in tree.iter('branch','heading','vymnote','floatimage'):
   count=tree.getpath(node).count('branch')
   try:
      href=node.get("href")[5:]
      paragraph=document.add_picture(imagesrt+href)
      paragraph.paragraph_format.left_indent = Inches(0.5*count-.5)
   except:
      try:
         if node.text.strip()!='None': #and node.get("href"):
            if node.tag=='heading' and count>0:
               paragraph=document.add_heading(node.text, level=count)
               paragraph.paragraph_format.left_indent = Inches(0.5*count-.5)
            if node.tag=='vymnote':
               paragraph=document.add_paragraph(node.text)
               paragraph.paragraph_format.left_indent = Inches(0.5*count-.5)
      except:
         six=9
document.save(target)

raw source