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 # The person who associated a work with this deed has dedicated # the work to the public domain by waiving all of his or her rights # to the work worldwide under copyright law, including all related # and neighboring rights, to the extent allowed by law. # You can copy, modify, distribute and perform the work, even for # commercial purposes, all without asking permission. # In no way are the patent or trademark rights of any person affected by # CC0, nor are the rights that other persons may have in the work or in # how the work is used, such as publicity or privacy rights. # Unless expressly stated otherwise, the person who associated a work with # this deed makes no warranties about the work, and disclaims liability # for all uses of the work, to the fullest extent permitted by applicable law. # When using or citing the work, you should not imply endorsement by the # author or the affirmer. # https://creativecommons.org/publicdomain/zero/1.0/ 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)