Visio/IronPython/Powershell – Part 3 – Shapesheet fun
See my previous posts:
- post 1: Visio/IronPython/Powershell – How to draw nice diagrams from the command line
- post 2: Visio/IronPython/Powershell – Part 2 – Drawing Diagrams from Data
Launch Visio 2007 and draw some shapes
The window opened larger than I wanted. Let’s resize it to something nicer
>>> vi.Dev.ResizeWindow( 1024, 768 )
Much better.
Now manually draw some shapes and set some formatting.
Select all the shapes, get all the cell values, and send it to excel
>>> vi.Select.All()
>>> cells = vi.ShapeSheet.GetCells()
>>> vi.Data.ExportToExcel( cells )Excel 2007 will launch
Each row is a cell.
The columns:
- A = the shape name
- B = the shape ID
- C = the name of the section the cell is in
- D = the row index of the cell
- E = the cell name
- F = cell’s formula value
- G = cell’s result value
- H = cell’s result value case to a double
You can export the data in other ways
- vi.Data.ExportToCSV( cells, “shapesheet.csv” )
- vi.Data.ExportToExcelXML( cells, “shapesheet.xml”)
Sometimes when working with a shapesheet, it’s convenient for shapes to display their shapenames …
>>> vi.Text.SetToField( VA.Fields.ObjectName )
Let’s make the text a little bigger
>>> vi.Text.SizeUp()
>>> vi.Text.SizeUp()Or we can set the text size to a specific value
>>> vi.Text.Size = 40
Now let’s manually connect some shapes with the Dynamic Connector
In this diagram:
- Sheet.1 is connected to Sheet.2
- Sheet.1 is connected to Sheet.3
- Sheet.2 is connected to Sheet.3
- Sheet.2 is connected to Sheet.4
Let’s discover this programmatically
>>> pairs = vi.Connect.GetConnectedShapePairs()
>>> for pair in pairs:
>>> print pair.ConnectedShape0.Name, "is connected to", pair.ConnectedShape1.Name, “by way of”, pair.ConnectingShape.NameThis will print …
Sheet.1 is connected to Sheet.2 by way of Dynamic connector
Sheet.2 is connected to Sheet.3 by way of Dynamic connector.6
Sheet.4 is connected to Sheet.2 by way of Dynamic connector.7
Sheet.3 is connected to Sheet.1 by way of Dynamic connector.8Using this information and looking up of the line endpoints for the connectors, you can identify create a directed graph. (QED)
Finally we can manually set cells,for example the PinX cell
Select all the rectangles
>>> vi.ShapeSheet.SetFormula( Cells.PinX, “0” )
And you’ll see all the shapes have moved
We could likewise manually set their color
>>> vi.ShapeSheet.SetFormula( Cells.FillForegnd, "rgb(0,0,255)" )
Published Thursday, January 29, 2009 9:43 PM by saveenr
Saveen Reddy's blog : Visio/IronPython/Powershell – Part 3 – Shapesheet fun
1 comment:
I have heard about another word repair tool. Besides, you can visit my blogs at: http://daspeac.livejournal.com/ or http://daspeac.blogspot.com/ where I’m trying to share my experience with regard to data corruption issues
Post a Comment