Categories

PowerShell and Visio: Opening a file 3

We have seen how to open a file and add the stencil that goes with it.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
$visio = New-Object -ComObject Visio.Application
$doc = $visio.Documents.Open("C:\Scripts\Visio\adtest.vsd")

## set active page
$pages = $visio.ActiveDocument.Pages
$page = $pages.Item(1)

## Add a stencil
$mysten = "C:\Program Files\Microsoft Office\Office14\Visio Content\1033\ADO_M.vss"
$stencil = $visio.Documents.Add($mysten)

$page.Shapes | Format-Table Name, Text, Id, Index -a

## create variables
foreach ($shape in $page.Shapes) {
    if ($shape.Name -like "Directory connector*") {
        New-Variable -Name $($Shape.Name) -Value $shape -Force
    }
    else {
        New-Variable -Name $($Shape.Text) -Value $shape -Force
    }
}

In this version we extend the script to display information about the shapes

Name                    Text       ID Index
----                    ----       -- -----
Domain                  manticore   1     1
Organizational unit     England    47     2
Directory connector                57     3
Organizational unit.58  Yorkshire  58     4
Directory connector.68             68     5
Organizational unit.69  York       69     6
Directory connector.79             79     7
Organizational unit.80  London     80     8
Directory connector.90             90     9
Organizational unit.91  Scotland   91    10
Directory connector.101           101    11
Organizational unit.102 Wales     102    12
Directory connector.112           112    13
Organizational unit.113 Ireland   113    14
Directory connector.123           123    15
Organizational unit.124 Portugal  124    16
Directory connector.134           134    17
Organizational unit.135 Lisbon    135    18
Directory connector.145           145    19
Organizational unit.146 Belgium   146    20
Directory connector.156           156    21
Organizational unit.157 Latvia    157    22
Directory connector.167           167    23

 

and then to create a variable for each shape.  Now we can start to manipulate the objects

Leave a Reply