0

I have an assignment to write a program in IronPython, that reads a Visio (2010) Document, and outputs in CMD what objects are in the active page, and how they are connected to each other.

So far, I have managed to open the Visio Document, but I can't display what's in it. This is my code until now:

import sys
import clr
import System
clr.AddReference("Microsoft.Office.Interop.Visio")
import Microsoft.Office.Interop.Visio
IVisio = Microsoft.Office.Interop.Visio
visapp = IVisio.ApplicationClass()
doc = visapp.Documents.Open("C:\\Users\\hari\\Desktop\\PythonExamples\\helloworld.vsd") 
page = visapp.ActivePage

elements = page.GetContainers(0)

for entry in elements:
    print entry

doc.Close()
visapp.Visible =0
visapp.Quit()

I found the method GetContainers in MSDN http://msdn.microsoft.com/en-us/library/office/ff765392(v=office.15).aspx but it's not outputing anything about the shapes that exist in the document. Does someone maybe have an idea?

falco
  • 165
  • 1
  • 4
  • 14
  • I changed your tags as the problem is (up until now) not related to python (and not even really to ironpython) and added a visio-tag as so seem to primarily require assistance with the visio SDK/automation API. – Simon Opelt Dec 12 '14 at 08:47
  • Maybe helpful: http://stackoverflow.com/questions/6456831/shape-connectors-in-visio There is no big difference if you do that in python or not. – Nikolay Dec 12 '14 at 16:33

1 Answers1

1

You could start with something like this... it's pretty straightforward I suppose..

.......
.......
page = visapp.ActivePage

for shape in page.Shapes:
    if not shape.OneD:
        print shape.Name + " '" + shape.Text + "'"
        for connectedShapeId in shape.ConnectedShapes(2, ""):
            connectedShape = page.Shapes.ItemFromID[connectedShapeId]
            print " => " + connectedShape.Name + " '" + connectedShape.Text + "'"
Nikolay
  • 10,752
  • 2
  • 23
  • 51