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?
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 + "'"
来源:https://stackoverflow.com/questions/27439603/reading-the-contents-of-microsoft-visio-2010-doc-in-ironpython