1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
using Microsoft.Office.Interop.Visio; using System.Runtime.InteropServices; using Visio = Microsoft.Office.Interop.Visio;
public void EnumObjectsVisio(string p_vsdFullPath) m_visioApp = new Visio.Application(); try { using (StreamWriter ws = new StreamWriter(VisioLog, false, Encoding.Unicode)) { uint ShapeCount = 0; Document oVsdDocument = m_visioApp.Documents.Open(p_vsdFullPath); try { Pages oPages = oVsdDocument.Pages; try { foreach (Page oPage in oPages) { Shapes oShapes = oPage.Shapes; try { if (oPage.Type == VisPageTypes.visTypeForeground) { double shapeHeight,shapeWidth, shapePinX, shapePinY; ws.WriteLine(@"{0}のページ:{1}", p_vsdFullPath, oPage.Document.Name); foreach (Shape oShape in oShapes) { ShapeCount++; //inch to millimeter shapeWidth = oShape.get_CellsU("Width").ResultIU; shapeHeight = oShape.get_CellsU("Height").ResultIU; shapePinX = oShape.get_CellsU("PinX").ResultIU; shapePinY = oShape.get_CellsU("PinY").ResultIU;
ws.WriteLine(@"No.{0} {1}, {2}, {3}, width:{4}, Height:{5}", ShapeCount, oShape.Name, oShape.Text, oShape.Type, shapeWidth, shapeHeight); ws.WriteLine(@" PinX:{0}, PinY:{1}", shapePinX, shapePinY); } } } finally { if (oShapes != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(oShapes); }
} } } finally { if (oPages != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(oPages); } } } finally { if (oVsdDocument != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(oVsdDocument); } } } } finally { m_visioApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(m_visioApp); m_visioApp = null; } }
|