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 Word Documents using bayoo-docx.

Here is an example Vym diagram:

To create a Word doc, from the diagram, use this command:

./vex.py docx map.xml doc/fab.docx "Concrete Plant" ./images/ aggie

Seperate a note and comment with the ✐ character. The Double Up, Up, Down, and Double Down translate to 1-4 in ranking:

Notice that you can also put images in the diagram.

Here is the source:

#!/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 lxml.etree import tostring
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]
   auth=sys.argv[6]
except:
   print('Error.  Need six arguments: <typedoc> <source> <target> <title> <imagesrt> <author>')

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)
head=''
note=''
flag=''
href=''
hrefc=0
count=0
for node in tree.iter('branch','heading','vymnote','floatimage','standardflag'):
   try:
      #if node.text.strip()!='None': #and node.get("href"):
      if node.tag=='branch':
         pcount=tree.getpath(node).count('branch')
         if len(head)>0:
            paragraph=document.add_heading(head+flag, level=count)
            paragraph.paragraph_format.left_indent = Inches(0.5*headc-.5)
            head=''
            flag=''
         if len(note)>0:
            try:
               comm=''
               parts=note.split('✐')
               comm=parts[1]
               note=parts[0]
            except:
               six=9
            if len(note)>0:
               paragraph=document.add_paragraph(note)
               paragraph.paragraph_format.left_indent = Inches(0.5*notec-.5)
            if len(comm)>0:
               comment = paragraph.add_comment(comm,author=auth) 
            note=''
         if len(href)>0:
             print('trying to add image:'+imagesrt+href)
            paragraph=document.add_picture(imagesrt+href)
            print('xx'+imagesrt+href)
            #paragraph.paragraph_format.left_indent = Inches(0.5*hrefc-.5)
            print('we have an image'+href)
            href='' 
         count=pcount
   except:
      six=9
   if node.tag=='floatimage':
      print('we have float')
      href=node.get("href")[12:]
      hrefc=tree.getpath(node).count('branch')
   try:
      if node.text.strip()!='None': #and node.get("href"):
         if node.tag=='standardflag':
            if node.text=='2arrow-up':
               flag='1️'
            if node.text=='arrow-up':
               flag='2️'
            if node.text=='arrow-down':
               flag='3️'
            if node.text=='2arrow-down':
               flag='4️'
         if node.tag=='heading' and count>0:
            head=node.text
            headc=count
            headc=tree.getpath(node).count('branch')
         if node.tag=='vymnote':
            note=node.text
            notec=count
            notec=tree.getpath(node).count('branch')
   except:
      six=9
document.save(target)

raw source