Package: vsdx
vsdx - A python library for processing Visio .vsdx files.vsdx files can be processed in two ways, directly via python code as in
example 1 below, or indirectly using a jinja template as in example 2For quick start documentation please seehttps://vsdx.readthedocs.io/en/latest/quickstart.htmlExample 1code to find a shape with specific text, remove it, and
then save the updated .vsdx file:fromvsdximportVisioFilefilename='my_file.vsdx'# open a visio filewithVisioFile(filename)asvis:# find shape by its text on first pageshape=vis.pages[0].find_shape_by_text('Shape to remove')# remove the shape if foundifshape:shape.remove()# save a new copyvis.save_vsdx('shape_removed.vsdx')Example 2creating a new vsdx file from a template and context data
using jinja.Note that as vsdx does not lend itself well to ordered statements like{% if something %}my content{% endif %}or{% for x in list_value %}x={{ x }}{% endfor %}this package provides mechanisms to help -
refer to tests for more details.fromvsdximportVisioFilefilename='my_template_file.vsdx'# file containing jinja codecontext={'value1':10,'list_value':[1,2,3]}# data for the templatewithVisioFile('my_template_file.vsdx')asvis:vis.jinja_render_vsdx(context=context)vis.save_vsdx('my_new_file.vsdx')Please refer to tests/test.py for more usage
examples in the form of pytest tests.Change Logv0.5.19: Fix Page.is_master_page prop and add testsv0.5.18: Add support for reading (not creating/saving) .vsdm files (macro-enabled)v0.5.17: Fix bug with adding multiple connectors to a vsdx with no existing master files/relsv0.5.16: Add support & commit hook tests for Python 3.11 and 3.12v0.5.15: Change DataProperty.value from field to property (get/set)v0.5.14: Add Page.find_shape_by_attr()v0.5.13: Update DataProperty class to get value of a property from V attrib or textv0.5.12: AddShape.fill_colorandShape.text_colorproperties with get and set testsv0.5.11: AddShape.find_shapes_by_regex()&Page.find_shapes_by_regex()- add check insave_vsdx()that file is open with more meaningfulVisioFileNotOpenerrorv0.5.10: Add Shape.angle propertyv0.5.9: Add tests for master shape text propertyv0.5.8: AddPage.master_base_idpropertyv0.5.7: Add support for nested shapes inPage.all_shapesandShape.all_shapes. AddPage.is_master_pageandShape.is_master_shape.v0.5.6: Fix error inShape.textwith missing master shape. ImproveVisioFile.remove_page_by_index()and addVisioFile.remove_page_by_name().v0.5.5: Added Shape.universal_name and used in Shape.set_start_and_finish(). Set Page.page_id on open file.v0.5.4: Added better (but still incomplete) support for adding connectors between shapesv0.5.3: Fixed missing deprecation dependency in setup.pyv0.5.2: deprecated Page.set_name() method and page.page_name property, in favour of Page.name. Unskipped test: test_shape_center(). Added find_shape.rst doc pagev0.5.1: added Page/Shape.find_shape_by_property_label_value()/find_shapes_by_property_label_value()v0.5.0: deprecated Page.shapes property Page/Shape.sub_shapes() methods in favour of Page/Shape.child_shapes property. Add Shape.all_shapes property, convert Page.all_shapes() method to propertyv0.4.20: Shape.set_cell_value()/set_cell_formula() create new cell if missing, add Media().rectangle and circle props, add Shape.bounds, relative_bounds, and end_arrow propsv0.4.19: correctly position new connector shapes between 'from' and 'to' shapesv0.4.18: add page.page_name, width and height propertiesv0.4.17: register xml namespaces to improve compatibility of xml outputv0.4.16: Add Geometry class to read Shape geometryv0.4.15: Add requirement for Jinja2 to packagev0.4.14: Include media/*.vsdx files in packagev0.4.13: Fix for master shape property inheritance / value overridesv0.4.12: Add support for absolute pathsv0.4.11: Add support for master shape data properties, with related testsv0.4.10: Add methods (Shape.find_shape_by_property_label()andShape.find_shapes_by_property_label) to find shape or shapes by data property name.v0.4.9: Add support for creating new connection between two objects. Fix ShapeProperty.value, and add label, sort_key, value_type and promptv0.4.8: Support nested loops/showifs and combo of loop and if in same shape.v0.4.7: Python 3.10.0rc1 added to test suite. AddShape.data_propertiesproperty, and new classShapePropertyto represent Visio Shape Datav0.4.6: Add support for nested jinja loops in one shapev0.4.5: Fix bug where some shapes have no parent, and inserting shape into empty pagev0.4.4: Added support for master page shape inheritance, ability to getShape.master_shape, ability to
update master shapes and persist changes to master shapes insave_vsdx()v0.4.3: Added support for including/excluding pages via Jinja with{% showif <statement> %}in page namev0.4.2: AddedVisioFile.add_page_at()method takingindexto allow insertion
at a specific point; AddedVisionFile.copy_page()method to copy an existing page
and insert at a specific index or relative to copied page (usingPagePositionenum).v0.4.1: Added support for self referencing calculations in Jinja statements,
such as{% set self.x = self x + n * 3.2 %}v0.4.0: AddedVisioFile.jinja_set_selfsto allow setting shape x and
y properties in Jinja template. Setting values, calculations, or if
statements are supported e.g.{% set self.x = 1.5 %}or{% set self.y = n * 3 %}or{% set self.x = 1.0 if n else 2.0 %}v0.3.5: AddedVisioFile.add_page()method and testsv0.3.4: AddedVisioFile.remove_page_by_index()method to remove a
page, with associated testv0.3.3: Added code of conduct and contributing guidesv0.3.2: updated README and updated tests for improved compatibilityv0.3.1: add jinja rendering support for if statements, viaVisioFile.jinja_render_vsdx()- similar to for loops but using a{% showif statement %}in text of group shape controls whether that
group shape is included in vsdx file rendered. Note that the showif
statement is replaced with a standard if statement around the group
shape prior to rendering. Refer to test.py::test_jinja_if() for an
examplev0.3.0: update jinja rendering to support for loops, where for
statement is at start of group shape text, endfor is automatically
inserted before processing. Refer to test.py::test_basic_jinja_loop()
for code and test_jinja_loop.vsdx for content.v0.2.10: addVisioFile.jinja_render_vsdx()- applying jinja
processing to Shape.text onlyv0.2.9: check that Page has shapes tag when in shape_copy(), add test
to copy shape to new pagev0.2.8: find max shape ID in Page before creating Shape inShape.copy(). Find and load master pages when file is opened, store
in VisioFile.master_page_objects and .master_pagesv0.2.7: addShape.copy()methodv0.2.6: addedPage.get_connectors_between()to get zero or many
connectors between two shapes, by shape id or text0.2.5: Add new Shape properties connected_shapes (list of Shape
objects) and connects (list of Connect objects) properties to allow
related shapes to be identified (i.e. shapes and connectors) and
provide information on the relationship, in new Connect object. Also
new properties of shape begin_x/y, end_x/y, plus height/width
setters0.2.4: Added find_replace(old, new) method to Shape and Page classes
to recursively replace old with new0.2.3: Updated tests to output files to an /out folder. Added test
vsdx file with compound shape. Updated Shape text getter/setter0.2.2: Added x & y location setters to Shape, and move(x_delta,
y_delta) method - both with related tests