1

I am trying to automate some translation work where I just need edit all the texts in Visio (vsdx) files, the diagram does not need to be changed.

I have been searching for ways to perform such action but I can't find anything useful.

How do I import vsdx to python, edit texts globally then export a vsdx?

Sergei Danielian
  • 4,938
  • 4
  • 36
  • 58
thf9527
  • 71
  • 2
  • 11

1 Answers1

2

First of all, you should read more about VSDX Drawing File Format. Here are several references:

  1. Visio VSDX Drawing File Format
  2. Introduction to the Visio file format (.vsdx)
  3. Manipulate the Visio file format programmatically

Also, get familiar with Open Packaging Conventions and XML or ECMA 376 - this standard the new vsdx is based on (tiny hint: vsdx is a usual archive).

After that you will figure out that basically there are a lot of libraries written even in python that works in some way with vsdx.

Update: as Nikolay politely noted, actually there are no so many libraries to work with this kind of files. So, my wording here (a lot of) is simply incorrect. On the contrary, there are few articles explaining how to deal with the vsdx format.

Sergei Danielian
  • 4,938
  • 4
  • 36
  • 58
  • 1
    Could you name at least one python library that can at least read and write vsdx files (you said that there are "a lot" of them)..? – Nikolay Jul 29 '18 at 16:43
  • Will the first one from the Google work for you? https://github.com/thiezn/visiopy Anyway, the spec is open, why not untar the file and find the XML that describe the text and work with it as you wish? – Sergei Danielian Jul 29 '18 at 16:56
  • I did a more detailed search, and you're right. My wording ("a lot") is simply incorrect - I will update my answer. Thx. – Sergei Danielian Jul 30 '18 at 02:56
  • 1
    I have figured it out and yes gahcep is right, the logic is to rename, unzip, operate on the XMLs. With the help of beautifulsoup I manage to edit all the texts easily. – thf9527 Jul 30 '18 at 12:19
  • 1
    can you please provide us a code sample for working on the underlying XML of the visio files? – Sankar Feb 11 '20 at 15:12
  • I used beautifulsoup to parse the XML within the vsdx, you can edit text by re-assigning items inside bs4.element.ResultSet to your desired text, then write the edited soup object to a new XML (or replace your old one) – thf9527 May 29 '20 at 05:00