Friday, January 30, 2009

Visio/IronPython/Powershell – Part 3 – Shapesheet fun

 

Visio/IronPython/Powershell – Part 3 – Shapesheet fun

See my previous posts:

Launch Visio 2007 and draw some shapes

image

The window opened larger than I wanted. Let’s resize it to something nicer

>>> vi.Dev.ResizeWindow( 1024, 768 )

image

Much better.

Now manually draw some shapes and set some formatting.

image

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

image

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 )

image

Let’s make the text a little bigger

>>> vi.Text.SizeUp()
>>> vi.Text.SizeUp()

image

Or we can set the text size to a specific value

>>> vi.Text.Size = 40

image

Now let’s manually connect some shapes with the Dynamic Connector

image

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.Name

This 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.8

Using 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

image

>>> vi.ShapeSheet.SetFormula( Cells.PinX, “0” )

And you’ll see all the shapes have moved

image

We could likewise manually set their color

>>> vi.ShapeSheet.SetFormula( Cells.FillForegnd, "rgb(0,0,255)" )

image

Published Thursday, January 29, 2009 9:43 PM by saveenr

Saveen Reddy's blog : Visio/IronPython/Powershell – Part 3 – Shapesheet fun

1 comment:

daspeac said...

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

Blog Archive