Python Script to Automatically Generate the Mental Model Diagram
Update: a new script was released in June 2009.
You will need to install the Python interpreter before you can run the script. Download the latest binary release for your platform. Next, download the script for the PC or the package for the Mac that David Verba converted from the PC version. This Mac version requires a different file format, which is zipped up in the download. For the PC, use either of the "grouping" files listed as Microsoft Word and Excel templates.Install Python, and then put the script and your file in the same folder. To run the script, click or double click it. A small window will appear with the names of all valid Word or Excel files listed, and a number to the left of each. At the command line prompt, type in the number associated with your file. If everything works correctly, an XML file (labeled with the extension "vsd") will be deposited in that folder, which should open with Visio or Omnigraffle.
In the PC version, each box can contain 48 character titles. If you change the cell color in the tower column or the task column, that box usually turns the same color in the diagram. Sometimes the tower turns a pale yellow or white instead, but I have not yet managed to debug it to find out why. In the Mac version, the colors you set the cells in Excel do not transfer to the diagram output. Yet. If you fix either of these things, let me know and I'll post the update here, along with your name and link.
I also welcome folks to post templates for some of the other spreadsheet and word processing applications that are proliferating these days. And, if you're interested in extending the script itself, you're more than welcome to post your additions or an entirely new script in another scripting language.
Caveat: The script (both on the PC and the Mac) is pretty finicky about the format of the Word or Excel file, and I won't be able to help you debug it. But if you leave comments here, perhaps the community will have some experience. The script doesn't know what to do with a space that comes at the end of a heading in Word, so it just stops. And, if your column headings in Excel aren't exactly right, it will also stop. The screen will flash and you will be left with...nothing. So be sure to check the format of your file first.
Comments
I thought I'd post a few known quirks of the script to help people figure out why some Task Towers are not being colored:
-- script doesn't like different heights of cells (ie. 15pxls vs. 17pxls)
FIX: highlight all rows in Excel and set height to 15pxls
-- script *sometimes* doesn't like a single quote (like in a contraction "don't")
-- script doesn't like an emdash [--]
Thanks
JR
Posted by: Jennifer Richardson | February 7, 2008 9:46 PM
Thanks Jen! I didn't know about the line height issue. Good to know!
Posted by: indi young | February 8, 2008 8:37 AM
You might find it easier to do this with Resolver One - and IronPython based spreadsheet that will let you embed your modeling code into the spreadsheet.
http://www.resolversystems.com/
Michael Foord
Posted by: Michael Foord | February 12, 2008 4:08 PM
Thank you Michael. If anyone does this, let me know. It would be good if it offers some additional flexibility to our Python script, such as using the font style and color from the cell in the XML version of the model.
Posted by: Indi Young | March 6, 2008 11:26 AM
Thanks Indi - awesome script (once I had the right version of python)! You just saved me a gazillion hours of work!
Donna
Posted by: Donna Spencer | May 2, 2008 8:09 PM
Thank you so much for sharing this script. Different types of task/diagram modifications have occurred to us when we saw the grouped data in post-it, Excel, and final diagram formats. Having this script made it effortless to regenerate a complete diagram.
The only thing I did was modify the "BOXHEIGHT" and "BOXWIDTH" parameters in the script to accommodate our rather long tasks. Thanks again!
Posted by: Beverly | June 5, 2008 6:01 PM
Today Python version 3 was released and the script doesn't seem to like it. The screen comes up and goes away without enough time to input any commands or see what's the issue. I'm not very versed on this but though I'd post FYI.
Posted by: Livia Labate | December 5, 2008 12:56 PM
Any advice for running this on Vista?
Posted by: Michele Marut | December 15, 2008 12:16 PM
In response to Jennifer Richardson's helpful submission on February 7th, 2008, the sometimes doesn't like apostrophes is because the script fails on Microsoft "curly" quotes. Plain text apostrophes work just fine. Should you come across one of these curly quotes (they are responsible for content problems everywhere) you can copy to the clipboard, and search and replace them with regular apostrophes.
Posted by: Eric Fain | January 15, 2009 4:24 PM
I believe there is a version of Python for Vista to download. The script will run on that without a problem. It's just that you need to get Python running on your OS first.
Posted by: Indi Young | January 27, 2009 11:32 AM
I installed Python on my Windows XP. The command dialog flashes and nothing happens for the Windows script as well as for other sample scripts from the Python installation. It does not look like it is a problem with formatting of the files. Any ideas?
Posted by: JV Siew | April 16, 2009 11:25 PM
I've really REALLY tried to get this working on XP and gotten so far...
the default 2.6.2 msi flashes up like Livia mentions above.
I then installed the active state version: http://www.activestate.com/activepython
this gets better results as I now have .xls and .txt output - but still no .vdx file : (
-------
[Indi adds from email]: It looks like it was saving in compatible mode via excel '07 that was my problem. The real problem was doing Save As... through excel '07.
Untampered with copies of your templates worked just fine.So now I've got my first visio MM!
Also, I installed the latest from the python site and had trouble getting it to
recognise the path through the environment variables, so I quickly gave up
and installed the activestate version; which behaved!
Posted by: ritchielee | June 3, 2009 4:32 AM
Livia, same issue here for Python 2.6.1 on Windows. Any work around?
Posted by: Vincent | June 5, 2009 4:50 AM
Make sure you've installed Python correctly, and use the template with the correct column headings.
For Windows XP:
- Install Python version 2.6.2 for Windows (latest supported by PyWin) - http://www.python.org/download/
- Install Pywin32 version pywin32-212.win32-py2.6.exe - http://sourceforge.net/projects/pywin32/
- Excel is required to run the script. The script does run with Excel 2003, but has not been tried with other versions
Posted by: Indi Young | June 5, 2009 10:34 AM
The script is working well for us to generate the "top" part of the mental model. Now I'm wondering if anybody has a version that can also generate the "bottom part" (content, functionality, features) from the same excel file?
Posted by: Steve R | August 7, 2009 12:12 AM
I just installed the latest version of Python for Mac (2.5) and downloaded the CSV to Visio package.
It wasn't working at first, so I compared my CSV file to the sample CSV file included in the CSVtoVisioPackage folder. I noticed there were no empty cells in the first few columns (MentalSpace and TaskGroup). So I filled in the columns and viola! It worked.
If you're having problems, mimic the layout of the sample CSV file and place all the files in the same folder.
Thanks, Indi! This script saved me tons of time I can now spend on analysis.
Dave
Posted by: Dave Cooksey | October 9, 2009 8:54 AM